diff --git a/Core/Code/Rendering/Overlays/mitkLabelOverlay3D.cpp b/Core/Code/Rendering/Overlays/mitkLabelOverlay3D.cpp index 0b09e9a10e..32b88e6a5d 100644 --- a/Core/Code/Rendering/Overlays/mitkLabelOverlay3D.cpp +++ b/Core/Code/Rendering/Overlays/mitkLabelOverlay3D.cpp @@ -1,107 +1,113 @@ /*=================================================================== 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 "mitkLabelOverlay3D.h" #include #include #include mitk::LabelOverlay3D::LabelOverlay3D() { } mitk::LabelOverlay3D::~LabelOverlay3D() { } mitk::LabelOverlay3D::LocalStorage::~LocalStorage() { } mitk::LabelOverlay3D::LocalStorage::LocalStorage() { // Create some text m_textSource = vtkSmartPointer::New(); m_textSource->SetText( "Hello" ); // Create a mapper vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetInputConnection( m_textSource->GetOutputPort() ); // Create a subclass of vtkActor: a vtkFollower that remains facing the camera m_follower = vtkSmartPointer::New(); m_follower->SetMapper( mapper ); m_follower->GetProperty()->SetColor( 1, 0, 0 ); // red m_follower->SetScale(1); } void mitk::LabelOverlay3D::UpdateVtkOverlay(mitk::BaseRenderer *renderer) { LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); ls->m_follower->SetPosition(GetPosition3D()[0],GetPosition3D()[1],GetPosition3D()[2]); ls->m_textSource->SetText(GetText().c_str()); + float color[3] = {1,1,1}; + float opacity = 1.0; + GetColor(color,renderer); + GetOpacity(opacity,renderer); + ls->m_follower->GetProperty()->SetColor(color[0], color[1], color[2]); + ls->m_follower->GetProperty()->SetOpacity(opacity); } void mitk::LabelOverlay3D::SetPosition3D(mitk::Point3D position3D) { mitk::Point3dProperty::Pointer position3dProperty = mitk::Point3dProperty::New(position3D); SetProperty("Pos3D", position3dProperty); } void mitk::LabelOverlay3D::SetText(std::string text) { SetStringProperty("text", text.c_str()); } void mitk::LabelOverlay3D::SetPosition3D(Point3D position3D, mitk::BaseRenderer *renderer) { mitk::Point3dProperty::Pointer position3dProperty = mitk::Point3dProperty::New(position3D); SetProperty("Pos3D", position3dProperty,renderer); } mitk::Point3D mitk::LabelOverlay3D::GetPosition3D() { mitk::Point3D position3D; GetPropertyValue < mitk::Point3D > ("Pos3D", position3D); return position3D; } std::string mitk::LabelOverlay3D::GetText() { std::string text; GetPropertyList()->GetStringProperty("text", text); return text; } mitk::Point3D mitk::LabelOverlay3D::GetPosition3D(mitk::BaseRenderer *renderer) { mitk::Point3D position3D; GetPropertyValue("Pos3D", position3D, renderer); return position3D; } -vtkSmartPointer mitk::LabelOverlay3D::GetVtkActor(BaseRenderer *renderer) +vtkSmartPointer mitk::LabelOverlay3D::GetVtkProp(BaseRenderer *renderer) { LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); ls->m_follower->SetCamera(renderer->GetVtkRenderer()->GetActiveCamera()); return ls->m_follower; } diff --git a/Core/Code/Rendering/Overlays/mitkLabelOverlay3D.h b/Core/Code/Rendering/Overlays/mitkLabelOverlay3D.h index 9701ba06ad..bdea4dc5fd 100644 --- a/Core/Code/Rendering/Overlays/mitkLabelOverlay3D.h +++ b/Core/Code/Rendering/Overlays/mitkLabelOverlay3D.h @@ -1,101 +1,100 @@ /*=================================================================== 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 LabelOverlay3D_H #define LabelOverlay3D_H #include "mitkVtkOverlay3D.h" #include #include #include #include namespace mitk { class MITK_CORE_EXPORT LabelOverlay3D : public mitk::VtkOverlay3D { public: /** \brief Internal class holding the mapper, actor, etc. for each of the 3 2D render windows */ /** * To render transveral, coronal, and sagittal, the mapper is called three times. * For performance reasons, the corresponding data for each view is saved in the * internal helper class LocalStorage. This allows rendering n views with just * 1 mitkMapper using n vtkMapper. * */ class MITK_CORE_EXPORT LocalStorage : public mitk::Overlay::BaseLocalStorage { public: /** \brief Actor of a 2D render window. */ vtkSmartPointer m_follower; vtkSmartPointer m_textSource; /** \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(); }; /** \brief The LocalStorageHandler holds all (three) LocalStorages for the three 2D render windows. */ mitk::LocalStorageHandler m_LSH; mitkClassMacro(LabelOverlay3D, mitk::VtkOverlay3D); itkNewMacro(LabelOverlay3D); void SetPosition3D(Point3D position3D); void SetText(std::string text); void SetPosition3D(Point3D position3D, mitk::BaseRenderer* renderer); Point3D GetPosition3D(); std::string GetText(); Point3D GetPosition3D(mitk::BaseRenderer* renderer); - void UpdateVtkOverlay(mitk::BaseRenderer *renderer); - protected: - virtual vtkSmartPointer GetVtkActor(BaseRenderer *renderer); + virtual vtkSmartPointer GetVtkProp(BaseRenderer *renderer); + void UpdateVtkOverlay(mitk::BaseRenderer *renderer); /** \brief explicit constructor which disallows implicit conversions */ explicit LabelOverlay3D(); /** \brief virtual destructor in order to derive from this class */ virtual ~LabelOverlay3D(); private: /** \brief copy constructor */ LabelOverlay3D( const LabelOverlay3D &); /** \brief assignment operator */ LabelOverlay3D &operator=(const LabelOverlay3D &); }; } // namespace mitk #endif // LabelOverlay3D_H diff --git a/Core/Code/Rendering/Overlays/mitkOverlay.cpp b/Core/Code/Rendering/Overlays/mitkOverlay.cpp index 3eb92fe79b..7dc93561a2 100644 --- a/Core/Code/Rendering/Overlays/mitkOverlay.cpp +++ b/Core/Code/Rendering/Overlays/mitkOverlay.cpp @@ -1,211 +1,261 @@ /*=================================================================== 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_PropertyList = mitk::PropertyList::New(); } mitk::Overlay::~Overlay() { } void mitk::Overlay::SetProperty(const char *propertyKey, BaseProperty* propertyValue, const mitk::BaseRenderer* renderer) { GetPropertyList(renderer)->SetProperty(propertyKey, propertyValue); } void mitk::Overlay::ReplaceProperty(const char *propertyKey, BaseProperty* propertyValue, const mitk::BaseRenderer* renderer) { GetPropertyList(renderer)->ReplaceProperty(propertyKey, propertyValue); } void mitk::Overlay::AddProperty(const char *propertyKey, BaseProperty* 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 char *propertyKey, const mitk::BaseRenderer* renderer) const { if(propertyKey==NULL) return NULL; //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 char* 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 char* 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 char* 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 char* 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 char* propertyKey, int intValue, mitk::BaseRenderer* renderer) { GetPropertyList(renderer)->SetProperty(propertyKey, mitk::IntProperty::New(intValue)); } void mitk::Overlay::SetBoolProperty( const char* propertyKey, bool boolValue, mitk::BaseRenderer* renderer/*=NULL*/ ) { GetPropertyList(renderer)->SetProperty(propertyKey, mitk::BoolProperty::New(boolValue)); } void mitk::Overlay::SetFloatProperty( const char* propertyKey, float floatValue, mitk::BaseRenderer* renderer/*=NULL*/ ) { GetPropertyList(renderer)->SetProperty(propertyKey, mitk::FloatProperty::New(floatValue)); } void mitk::Overlay::SetStringProperty( const char* propertyKey, const char* stringValue, mitk::BaseRenderer* renderer/*=NULL*/ ) { GetPropertyList(renderer)->SetProperty(propertyKey, mitk::StringProperty::New(stringValue)); } void mitk::Overlay::SetText(std::string text) { SetStringProperty("text", text.c_str()); } std::string mitk::Overlay::GetText() { std::string text; GetPropertyList()->GetStringProperty("text", text); return text; } +bool mitk::Overlay::GetColor(float rgb[], mitk::BaseRenderer* renderer, const char* 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 char* 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 char* 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 char* 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 char* 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 char* 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 char *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::PropertyList::Pointer mitk::Overlay::BaseLocalStorage::GetPropertyList() { if (m_PropertyList.IsNull()) m_PropertyList = mitk::PropertyList::New(); return m_PropertyList; } diff --git a/Core/Code/Rendering/Overlays/mitkOverlay.h b/Core/Code/Rendering/Overlays/mitkOverlay.h index ed98ac1a2d..9648c7619c 100644 --- a/Core/Code/Rendering/Overlays/mitkOverlay.h +++ b/Core/Code/Rendering/Overlays/mitkOverlay.h @@ -1,381 +1,409 @@ /*=================================================================== 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 #include #include #include "mitkBaseRenderer.h" namespace mitk { class MITK_CORE_EXPORT Overlay : public itk::Object { public: struct Bounds { - Point2D Position; - Point2D Size; + itk::Point Position; + itk::Point Size; }; typedef std::map MapOfPropertyLists; /** \brief Base class for mapper specific rendering ressources. */ class MITK_CORE_EXPORT BaseLocalStorage { public: bool IsGenerateDataRequired(mitk::BaseRenderer *renderer,mitk::Overlay *overlay); inline void UpdateGenerateDataTime() { m_LastGenerateDataTime.Modified(); } PropertyList::Pointer GetPropertyList(); inline itk::TimeStamp & GetLastGenerateDataTime() { return m_LastGenerateDataTime; } protected: /** \brief timestamp of last update of stored data */ itk::TimeStamp m_LastGenerateDataTime; PropertyList::Pointer m_PropertyList; }; - virtual void AddOverlay(BaseRenderer *renderer) = 0; - virtual void RemoveOverlay(BaseRenderer *renderer) = 0; - virtual void UpdateOverlay(BaseRenderer *renderer) = 0; - - virtual Bounds GetBoundsOnDisplay(BaseRenderer *renderer) = 0; - virtual void SetBoundsOnDisplay(BaseRenderer *renderer, Bounds) = 0; - //##Documentation //## @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 char *propertyKey, BaseProperty* property, const mitk::BaseRenderer* renderer = NULL); //##Documentation //## @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 DataNode. //## @sa GetProperty //## @sa m_PropertyList //## @sa m_MapOfPropertyLists void ReplaceProperty(const char *propertyKey, BaseProperty* property, const mitk::BaseRenderer* renderer = NULL); //##Documentation //## @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 char *propertyKey, BaseProperty* property, const mitk::BaseRenderer* renderer = NULL, bool overwrite = false); //##Documentation //## @brief Get the PropertyList of the @a renderer. If @a renderer is @a //## NULL, the BaseRenderer-independent PropertyList of this DataNode //## is returned. //## @sa GetProperty //## @sa m_PropertyList //## @sa m_MapOfPropertyLists mitk::PropertyList* GetPropertyList(const mitk::BaseRenderer* renderer = NULL) const; //##Documentation //## @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); //##Documentation //## @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 DataNode is queried. //## @sa GetPropertyList //## @sa m_PropertyList //## @sa m_MapOfPropertyLists mitk::BaseProperty* GetProperty(const char *propertyKey, const mitk::BaseRenderer* renderer = NULL) const; //##Documentation //## @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 DataNode is queried. //## @sa GetPropertyList //## @sa m_PropertyList //## @sa m_MapOfPropertyLists template bool GetProperty(itk::SmartPointer &property, const char *propertyKey, const mitk::BaseRenderer* renderer = NULL) const { property = dynamic_cast(GetProperty(propertyKey, renderer)); return property.IsNotNull(); } //##Documentation //## @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 DataNode is queried. //## @sa GetPropertyList //## @sa m_PropertyList //## @sa m_MapOfPropertyLists template bool GetProperty(T* &property, const char *propertyKey, const mitk::BaseRenderer* renderer = NULL) const { property = dynamic_cast(GetProperty(propertyKey, renderer)); return property!=NULL; } //##Documentation //## @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 char* propertyKey, T & value, mitk::BaseRenderer* renderer=NULL) const { GenericProperty* gp= dynamic_cast*>(GetProperty(propertyKey, renderer)); if ( gp != NULL ) { value = gp->GetValue(); return true; } return false; } //##Documentation //## @brief Convenience access method for bool properties (instances of //## BoolProperty) //## @return @a true property was found bool GetBoolProperty(const char* propertyKey, bool &boolValue, mitk::BaseRenderer* renderer = NULL) const; //##Documentation //## @brief Convenience access method for int properties (instances of //## IntProperty) //## @return @a true property was found bool GetIntProperty(const char* propertyKey, int &intValue, mitk::BaseRenderer* renderer=NULL) const; //##Documentation //## @brief Convenience access method for float properties (instances of //## FloatProperty) //## @return @a true property was found bool GetFloatProperty(const char* propertyKey, float &floatValue, mitk::BaseRenderer* renderer = NULL) const; //##Documentation //## @brief Convenience access method for string properties (instances of //## StringProperty) //## @return @a true property was found bool GetStringProperty(const char* propertyKey, std::string& string, mitk::BaseRenderer* renderer = NULL) const; //##Documentation //## @brief Convenience method for setting int properties (instances of //## IntProperty) void SetIntProperty(const char* propertyKey, int intValue, mitk::BaseRenderer* renderer=NULL); //##Documentation //## @brief Convenience method for setting int properties (instances of //## IntProperty) void SetBoolProperty(const char* propertyKey, bool boolValue, mitk::BaseRenderer* renderer=NULL); //##Documentation //## @brief Convenience method for setting int properties (instances of //## IntProperty) void SetFloatProperty(const char* propertyKey, float floatValue, mitk::BaseRenderer* renderer=NULL); //##Documentation //## @brief Convenience method for setting int properties (instances of //## IntProperty) void SetStringProperty(const char* propertyKey, const char* string, mitk::BaseRenderer* renderer=NULL); //##Documentation //## @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 char* propertyKey, mitk::BaseRenderer* renderer, bool defaultIsOn = true) const { if(propertyKey==NULL) return defaultIsOn; GetBoolProperty(propertyKey, defaultIsOn, renderer); return defaultIsOn; } //##Documentation //## @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, mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "name") const { return GetStringProperty(propertyKey, nodeName, renderer); } //##Documentation //## @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 { mitk::StringProperty* sp = dynamic_cast(this->GetProperty("name")); if (sp == NULL) return ""; return sp->GetValue(); } //##Documentation //## @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 char* name) { if (name == NULL) return; this->SetProperty("name", StringProperty::New(name)); } //##Documentation //## @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) { this->SetName(name.c_str()); } + //##Documentation + //## @brief Convenience access method for color properties (instances of + //## ColorProperty) + //## @return @a true property was found + bool GetColor(float rgb[], mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "color") const; + //##Documentation + //## @brief Convenience method for setting color properties (instances of + //## ColorProperty) + void SetColor(const mitk::Color &color, mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "color"); + //##Documentation + //## @brief Convenience method for setting color properties (instances of + //## ColorProperty) + void SetColor(float red, float green, float blue, mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "color"); + //##Documentation + //## @brief Convenience method for setting color properties (instances of + //## ColorProperty) + void SetColor(const float rgb[], mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "color"); + //##Documentation + //## @brief Convenience access method for opacity properties (instances of + //## FloatProperty) + //## @return @a true property was found + bool GetOpacity(float &opacity, mitk::BaseRenderer* renderer, const char* propertyKey = "opacity") const; + //##Documentation + //## @brief Convenience method for setting opacity properties (instances of + //## FloatProperty) + void SetOpacity(float opacity, mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "opacity"); + + void SetText(std::string text); std::string GetText(); //##Documentation //## @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, mitk::BaseRenderer* renderer, const char* propertyKey = "visible") const { return GetBoolProperty(propertyKey, visible, renderer); } //##Documentation //## @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(mitk::BaseRenderer* renderer, const char* propertyKey = "visible", bool defaultIsOn = true) const { return IsOn(propertyKey, renderer, defaultIsOn); } //##Documentation //## @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, mitk::BaseRenderer* renderer = NULL, const char* propertyKey = "visible"); + virtual void AddOverlay(BaseRenderer *renderer) = 0; + virtual void RemoveOverlay(BaseRenderer *renderer) = 0; + virtual void UpdateOverlay(BaseRenderer *renderer) = 0; + + virtual Bounds GetBoundsOnDisplay(BaseRenderer *renderer) = 0; + virtual void SetBoundsOnDisplay(BaseRenderer *renderer, Bounds) = 0; + mitkClassMacro(Overlay, itk::Object); protected: /** \brief explicit constructor which disallows implicit conversions */ explicit Overlay(); /** \brief virtual destructor in order to derive from this class */ virtual ~Overlay(); //##Documentation //## @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; //##Documentation //## @brief Map associating each BaseRenderer with its own PropertyList mutable MapOfPropertyLists m_MapOfPropertyLists; //##Documentation //## @brief Timestamp of the last change of m_Data itk::TimeStamp m_DataReferenceChangedTime; unsigned long m_PropertyListModifiedObserverTag; private: /** \brief copy constructor */ Overlay( const Overlay &); /** \brief assignment operator */ Overlay &operator=(const Overlay &); }; } // namespace mitk #endif // OVERLAY_H diff --git a/Core/Code/Rendering/Overlays/mitkOverlayManager.cpp b/Core/Code/Rendering/Overlays/mitkOverlayManager.cpp index bab451362c..c88b68d2e3 100644 --- a/Core/Code/Rendering/Overlays/mitkOverlayManager.cpp +++ b/Core/Code/Rendering/Overlays/mitkOverlayManager.cpp @@ -1,89 +1,130 @@ /*=================================================================== 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 "mitkOverlayManager.h" #include "usGetModuleContext.h" const std::string mitk::OverlayManager::PROP_ID = "org.mitk.services.OverlayManager.ID"; mitk::OverlayManager::OverlayManager() { m_id = this->RegisterMicroservice(); } mitk::OverlayManager::~OverlayManager() { + BaseRendererLSMap::iterator it; + for ( it=m_BaseRendererMap.begin() ; it != m_BaseRendererMap.end(); it++ ) + { + delete (*it).second; + } + m_BaseRendererMap.clear(); +} + +void mitk::OverlayManager::AddBaseRenderer(mitk::BaseRenderer* renderer) +{ + LocalStorage *l = m_BaseRendererMap[ renderer ]; + if(!l) + { + l = new LocalStorage; + m_BaseRendererMap[ renderer ] = l; + } } void mitk::OverlayManager::AddOverlay(mitk::Overlay::Pointer overlay) { m_OverlayList.push_back(overlay); + BaseRendererLSMap::iterator it; + for ( it=m_BaseRendererMap.begin() ; it != m_BaseRendererMap.end(); it++ ) + { + overlay->AddOverlay((*it).first); + } +} + +void mitk::OverlayManager::RemoveOverlay(mitk::Overlay::Pointer overlay) +{ + m_OverlayList.remove(overlay); + BaseRendererLSMap::iterator it; + for ( it=m_BaseRendererMap.begin() ; it != m_BaseRendererMap.end(); it++ ) + { + overlay->RemoveOverlay((*it).first); + } +} + +void mitk::OverlayManager::RemoveAllOverlays() +{ + std::list::iterator it; + for ( it=m_OverlayList.begin() ; it != m_OverlayList.end(); it++ ) + { + RemoveOverlay(*it); + } + m_OverlayList.clear(); } void mitk::OverlayManager::UpdateOverlays(mitk::BaseRenderer* baseRenderer) { - for(int i=0 ; i::iterator it; + for ( it=m_OverlayList.begin() ; it != m_OverlayList.end(); it++ ) { - mitk::Overlay::Pointer overlay = m_OverlayList[i]; - overlay->UpdateOverlay(baseRenderer); + (*it)->UpdateOverlay(baseRenderer); } } mitk::OverlayManager::LocalStorage::~LocalStorage() { } mitk::OverlayManager::LocalStorage::LocalStorage() { } std::string mitk::OverlayManager::RegisterMicroservice() { mitk::ServiceProperties properties; static int ID = 0; std::string id_str = static_cast( &(std::ostringstream() << ID) )->str(); properties[mitk::OverlayManager::PROP_ID] = id_str; mitk::ModuleContext* moduleContext = mitk::GetModuleContext(); m_Registration = moduleContext->RegisterService(this,properties); ID++; return id_str; } void mitk::OverlayManager::UnregisterMicroservice() { if(m_Registration =! NULL) { m_Registration.Unregister(); } } mitk::OverlayManager::Pointer mitk::OverlayManager::GetServiceInstance(int ID) { std::string id_str = static_cast( &(std::ostringstream() << ID) )->str(); mitk::ModuleContext* moduleContext = mitk::GetModuleContext(); std::string filter = "("+PROP_ID + "="+id_str+")"; std::list serref = moduleContext->GetServiceReferences("org.mitk.services.OverlayManager",filter); if(serref.size()==0) { return mitk::OverlayManager::New(); } else { mitk::OverlayManager::Pointer om = moduleContext->GetService(serref.front()); return om; } } diff --git a/Core/Code/Rendering/Overlays/mitkOverlayManager.h b/Core/Code/Rendering/Overlays/mitkOverlayManager.h index a8a5817f7d..bc828ae106 100644 --- a/Core/Code/Rendering/Overlays/mitkOverlayManager.h +++ b/Core/Code/Rendering/Overlays/mitkOverlayManager.h @@ -1,111 +1,113 @@ /*=================================================================== 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 OVERLAYMANAGER_H #define OVERLAYMANAGER_H #include "MitkExports.h" #include #include #include "mitkOverlay.h" #include "mitkBaseRenderer.h" #include "mitkLocalStorageHandler.h" // Microservices #include #include #include #include namespace mitk { class MITK_CORE_EXPORT OverlayManager : public itk::LightObject { public: mitkClassMacro(OverlayManager, itk::LightObject); itkNewMacro(OverlayManager); void AddOverlay(Overlay::Pointer overlay); - void UpdateOverlays(BaseRenderer *baseRenderer); + void RemoveOverlay(Overlay::Pointer overlay); + void RemoveAllOverlays(); void UnregisterMicroservice(); static const std::string PROP_ID; static OverlayManager::Pointer GetServiceInstance(int ID = 0); /** \brief Base class for mapper specific rendering ressources. */ class MITK_CORE_EXPORT LocalStorage { public: /** \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(); -// bool IsGenerateDataRequired(mitk::BaseRenderer *renderer,mitk::OverlayManager *overlaymanager); - 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 The LocalStorageHandler holds all (three) LocalStorages for the three 2D render windows. */ - mitk::LocalStorageHandler m_LSH; + typedef std::map BaseRendererLSMap; + + void AddBaseRenderer(BaseRenderer* renderer); + void UpdateOverlays(BaseRenderer *baseRenderer); protected: /** \brief explicit constructor which disallows implicit conversions */ explicit OverlayManager(); - /** \brief virtual destructor in order to derive from this class */ - virtual ~OverlayManager(); + ~OverlayManager(); private: - std::vector m_OverlayList; + std::list m_OverlayList; + + BaseRendererLSMap m_BaseRendererMap; /** \brief copy constructor */ OverlayManager( const OverlayManager &); /** \brief assignment operator */ OverlayManager &operator=(const OverlayManager &); std::string RegisterMicroservice(); mitk::ServiceRegistration m_Registration; std::string m_id; }; } // namespace mitk US_DECLARE_SERVICE_INTERFACE(mitk::OverlayManager, "org.mitk.services.OverlayManager") #endif // OVERLAYMANAGER_H diff --git a/Core/Code/Rendering/Overlays/mitkTextOverlay2D.cpp b/Core/Code/Rendering/Overlays/mitkTextOverlay2D.cpp index 69d73a12cb..ba76a78dc1 100644 --- a/Core/Code/Rendering/Overlays/mitkTextOverlay2D.cpp +++ b/Core/Code/Rendering/Overlays/mitkTextOverlay2D.cpp @@ -1,53 +1,54 @@ /*=================================================================== 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 mitk::TextOverlay2D::TextOverlay2D() { } mitk::TextOverlay2D::~TextOverlay2D() { } mitk::TextOverlay2D::LocalStorage::~LocalStorage() { } mitk::TextOverlay2D::LocalStorage::LocalStorage() { m_textActor = vtkSmartPointer::New(); } -void mitk::TextOverlay2D::UpdateVtkOverlay(mitk::BaseRenderer *renderer) +void mitk::TextOverlay2D::UpdateVtkOverlay2D(mitk::BaseRenderer *renderer) { LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); ls->m_textActor->GetTextProperty()->SetFontSize ( 24 ); ls->m_textActor->SetPosition2 ( 10, 40 ); ls->m_textActor->SetInput ( "Hello world" ); ls->m_textActor->GetTextProperty()->SetColor ( 1.0,0.0,0.0 ); } vtkSmartPointer mitk::TextOverlay2D::GetVtkActor2D(BaseRenderer *renderer) { - + LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); + return ls->m_textActor; } diff --git a/Core/Code/Rendering/Overlays/mitkTextOverlay2D.h b/Core/Code/Rendering/Overlays/mitkTextOverlay2D.h index b013333624..937e12ec96 100644 --- a/Core/Code/Rendering/Overlays/mitkTextOverlay2D.h +++ b/Core/Code/Rendering/Overlays/mitkTextOverlay2D.h @@ -1,96 +1,95 @@ /*=================================================================== 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 "mitkVtkOverlay2D.h" #include #include #include namespace mitk { class MITK_CORE_EXPORT TextOverlay2D : public mitk::VtkOverlay2D { public: /** \brief Internal class holding the mapper, actor, etc. for each of the 3 2D render windows */ /** * To render transveral, coronal, and sagittal, the mapper is called three times. * For performance reasons, the corresponding data for each view is saved in the * internal helper class LocalStorage. This allows rendering n views with just * 1 mitkMapper using n vtkMapper. * */ class MITK_CORE_EXPORT LocalStorage : public mitk::Overlay::BaseLocalStorage { public: /** \brief Actor of a 2D render window. */ vtkSmartPointer m_textActor; /** \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(); }; /** \brief The LocalStorageHandler holds all (three) LocalStorages for the three 2D render windows. */ mitk::LocalStorageHandler m_LSH; mitkClassMacro(TextOverlay2D, mitk::VtkOverlay2D); itkNewMacro(TextOverlay2D); void SetPosition(Point3D position3D); void SetText(std::string text); void SetPosition(Point3D position3D, mitk::BaseRenderer* renderer); Point3D GetPosition(); std::string GetText(); Point3D GetPosition(mitk::BaseRenderer* renderer); - void UpdateVtkOverlay(mitk::BaseRenderer *renderer); - protected: virtual vtkSmartPointer GetVtkActor2D(BaseRenderer *renderer); + 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 diff --git a/Core/Code/Rendering/Overlays/mitkTextOverlay3D.cpp b/Core/Code/Rendering/Overlays/mitkTextOverlay3D.cpp index 763798e785..cef70bfae1 100644 --- a/Core/Code/Rendering/Overlays/mitkTextOverlay3D.cpp +++ b/Core/Code/Rendering/Overlays/mitkTextOverlay3D.cpp @@ -1,65 +1,71 @@ /*=================================================================== 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 "mitkTextOverlay3D.h" #include #include #include mitk::TextOverlay3D::TextOverlay3D() { } mitk::TextOverlay3D::~TextOverlay3D() { } mitk::TextOverlay3D::LocalStorage::~LocalStorage() { } mitk::TextOverlay3D::LocalStorage::LocalStorage() { // Create some text m_textSource = vtkSmartPointer::New(); // Create a mapper vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetInputConnection( m_textSource->GetOutputPort() ); // Create a subclass of vtkActor: a vtkFollower that remains facing the camera m_follower = vtkSmartPointer::New(); m_follower->SetMapper( mapper ); m_follower->GetProperty()->SetColor( 1, 0, 0 ); // red m_follower->SetScale(1); } void mitk::TextOverlay3D::UpdateVtkOverlay(mitk::BaseRenderer *renderer) { LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); ls->m_follower->SetPosition(GetPosition3D()[0],GetPosition3D()[1],GetPosition3D()[2]); ls->m_textSource->SetText(GetText().c_str()); + float color[3] = {1,1,1}; + float opacity = 1.0; + GetColor(color,renderer); + GetOpacity(opacity,renderer); + ls->m_follower->GetProperty()->SetColor(color[0], color[1], color[2]); + ls->m_follower->GetProperty()->SetOpacity(opacity); } -vtkSmartPointer mitk::TextOverlay3D::GetVtkActor(BaseRenderer *renderer) +vtkSmartPointer mitk::TextOverlay3D::GetVtkProp(BaseRenderer *renderer) { LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); ls->m_follower->SetCamera(renderer->GetVtkRenderer()->GetActiveCamera()); return ls->m_follower; } diff --git a/Core/Code/Rendering/Overlays/mitkTextOverlay3D.h b/Core/Code/Rendering/Overlays/mitkTextOverlay3D.h index 5e7e866015..d867f6ebbb 100644 --- a/Core/Code/Rendering/Overlays/mitkTextOverlay3D.h +++ b/Core/Code/Rendering/Overlays/mitkTextOverlay3D.h @@ -1,89 +1,88 @@ /*=================================================================== 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 TextOverlay3D_H #define TextOverlay3D_H #include "mitkVtkOverlay3D.h" #include #include #include #include namespace mitk { class MITK_CORE_EXPORT TextOverlay3D : public mitk::VtkOverlay3D { public: /** \brief Internal class holding the mapper, actor, etc. for each of the 3 2D render windows */ /** * To render transveral, coronal, and sagittal, the mapper is called three times. * For performance reasons, the corresponding data for each view is saved in the * internal helper class LocalStorage. This allows rendering n views with just * 1 mitkMapper using n vtkMapper. * */ class MITK_CORE_EXPORT LocalStorage : public mitk::Overlay::BaseLocalStorage { public: /** \brief Actor of a 2D render window. */ vtkSmartPointer m_follower; vtkSmartPointer m_textSource; /** \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(); }; /** \brief The LocalStorageHandler holds all (three) LocalStorages for the three 2D render windows. */ mitk::LocalStorageHandler m_LSH; mitkClassMacro(TextOverlay3D, mitk::VtkOverlay3D); itkNewMacro(TextOverlay3D); - void UpdateVtkOverlay(mitk::BaseRenderer *renderer); - protected: - virtual vtkSmartPointer GetVtkActor(BaseRenderer *renderer); + virtual vtkSmartPointer GetVtkProp(BaseRenderer *renderer); + void UpdateVtkOverlay(mitk::BaseRenderer *renderer); /** \brief explicit constructor which disallows implicit conversions */ explicit TextOverlay3D(); /** \brief virtual destructor in order to derive from this class */ virtual ~TextOverlay3D(); private: /** \brief copy constructor */ TextOverlay3D( const TextOverlay3D &); /** \brief assignment operator */ TextOverlay3D &operator=(const TextOverlay3D &); }; } // namespace mitk #endif // TextOverlay3D_H diff --git a/Core/Code/Rendering/Overlays/mitkVtkOverlay.cpp b/Core/Code/Rendering/Overlays/mitkVtkOverlay.cpp index bf514b85d1..40dc961918 100644 --- a/Core/Code/Rendering/Overlays/mitkVtkOverlay.cpp +++ b/Core/Code/Rendering/Overlays/mitkVtkOverlay.cpp @@ -1,59 +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 "mitkVtkOverlay.h" +#include mitk::VtkOverlay::VtkOverlay() { } mitk::VtkOverlay::~VtkOverlay() { } void mitk::VtkOverlay::UpdateOverlay(mitk::BaseRenderer *renderer) { - vtkSmartPointer vtkActor = GetVtkActor(renderer); + vtkSmartPointer prop = GetVtkProp(renderer); if(!IsVisible(renderer)) { - vtkActor->SetVisibility(false); + prop->SetVisibility(false); return; } else { - vtkActor->SetVisibility(true); + + prop->SetVisibility(true); UpdateVtkOverlay(renderer); } } void mitk::VtkOverlay::AddOverlay(mitk::BaseRenderer *renderer) { + UpdateOverlay(renderer); vtkSmartPointer vtkProp = GetVtkProp(renderer); if(!renderer->GetVtkRenderer()->HasViewProp(vtkProp)) { renderer->GetVtkRenderer()->AddViewProp(vtkProp); } } void mitk::VtkOverlay::RemoveOverlay(mitk::BaseRenderer *renderer) { vtkSmartPointer vtkProp = GetVtkProp(renderer); if(!renderer->GetVtkRenderer()->HasViewProp(vtkProp)) { renderer->GetVtkRenderer()->RemoveViewProp(vtkProp); } } diff --git a/Core/Code/Rendering/Overlays/mitkVtkOverlay.h b/Core/Code/Rendering/Overlays/mitkVtkOverlay.h index 587e6585e7..c9c367e898 100644 --- a/Core/Code/Rendering/Overlays/mitkVtkOverlay.h +++ b/Core/Code/Rendering/Overlays/mitkVtkOverlay.h @@ -1,63 +1,63 @@ /*=================================================================== 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 VTKOVERLAY_H #define VTKOVERLAY_H #include #include #include #include "mitkOverlay.h" #include "mitkBaseRenderer.h" #include +#include namespace mitk { class MITK_CORE_EXPORT VtkOverlay : public Overlay { public: - virtual void UpdateVtkOverlay(BaseRenderer *renderer) = 0; + mitkClassMacro(VtkOverlay, Overlay); void UpdateOverlay(BaseRenderer *renderer); void AddOverlay(BaseRenderer *renderer); void RemoveOverlay(BaseRenderer *renderer); - mitkClassMacro(VtkOverlay, Overlay); - protected: virtual vtkSmartPointer GetVtkProp(BaseRenderer *renderer) = 0; + virtual void UpdateVtkOverlay(BaseRenderer *renderer) = 0; /** \brief explicit constructor which disallows implicit conversions */ explicit VtkOverlay(); /** \brief virtual destructor in order to derive from this class */ virtual ~VtkOverlay(); private: /** \brief copy constructor */ VtkOverlay( const VtkOverlay &); /** \brief assignment operator */ VtkOverlay &operator=(const VtkOverlay &); }; } // namespace mitk #endif // OVERLAY_H diff --git a/Core/Code/Rendering/Overlays/mitkVtkOverlay2D.cpp b/Core/Code/Rendering/Overlays/mitkVtkOverlay2D.cpp index ec73737940..7a623a4c20 100644 --- a/Core/Code/Rendering/Overlays/mitkVtkOverlay2D.cpp +++ b/Core/Code/Rendering/Overlays/mitkVtkOverlay2D.cpp @@ -1,49 +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. ===================================================================*/ #include "mitkVtkOverlay2D.h" #include mitk::VtkOverlay2D::VtkOverlay2D() { } mitk::VtkOverlay2D::~VtkOverlay2D() { } mitk::Overlay::Bounds mitk::VtkOverlay2D::GetBoundsOnDisplay(mitk::BaseRenderer *renderer) { mitk::Overlay::Bounds bounds; vtkSmartPointer actor = GetVtkActor2D(renderer); bounds.Position = actor->GetPosition(); bounds.Size = actor->GetPosition2(); } void mitk::VtkOverlay2D::SetBoundsOnDisplay(mitk::BaseRenderer *renderer, mitk::Overlay::Bounds bounds) { vtkSmartPointer actor = GetVtkActor2D(renderer); actor->SetPosition(bounds.Position[0],bounds.Position[1]); actor->SetPosition2(bounds.Size[0],bounds.Size[1]); } +void mitk::VtkOverlay2D::UpdateVtkOverlay(mitk::BaseRenderer *renderer) +{ + vtkSmartPointer prop = GetVtkActor2D(renderer); + float color[3] = {1,1,1}; + float opacity = 1.0; + GetColor(color,renderer); + GetOpacity(opacity,renderer); + prop->GetProperty()->SetColor(color[0], color[1], color[2]); + prop->GetProperty()->SetOpacity(opacity); + UpdateVtkOverlay2D(renderer); +} + vtkSmartPointer mitk::VtkOverlay2D::GetVtkProp(mitk::BaseRenderer *renderer) { return GetVtkActor2D(renderer); } diff --git a/Core/Code/Rendering/Overlays/mitkVtkOverlay2D.h b/Core/Code/Rendering/Overlays/mitkVtkOverlay2D.h index a59e2425cf..9de967468c 100644 --- a/Core/Code/Rendering/Overlays/mitkVtkOverlay2D.h +++ b/Core/Code/Rendering/Overlays/mitkVtkOverlay2D.h @@ -1,63 +1,65 @@ /*=================================================================== 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 #include #include "mitkVtkOverlay.h" #include "mitkBaseRenderer.h" #include #include +#include namespace mitk { class MITK_CORE_EXPORT VtkOverlay2D : public VtkOverlay { public: + mitkClassMacro(VtkOverlay2D, VtkOverlay); virtual Overlay::Bounds GetBoundsOnDisplay(BaseRenderer *renderer); virtual void SetBoundsOnDisplay(BaseRenderer *renderer, Overlay::Bounds bounds); - mitkClassMacro(VtkOverlay2D, VtkOverlay); - protected: vtkSmartPointer GetVtkProp(BaseRenderer *renderer); + virtual void UpdateVtkOverlay(BaseRenderer *renderer); + virtual void UpdateVtkOverlay2D(BaseRenderer *renderer) = 0; virtual vtkSmartPointer GetVtkActor2D(BaseRenderer *renderer) = 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/Core/Code/Rendering/Overlays/mitkVtkOverlay3D.cpp b/Core/Code/Rendering/Overlays/mitkVtkOverlay3D.cpp index c4d553ac65..e1e939c0f6 100644 --- a/Core/Code/Rendering/Overlays/mitkVtkOverlay3D.cpp +++ b/Core/Code/Rendering/Overlays/mitkVtkOverlay3D.cpp @@ -1,35 +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. ===================================================================*/ #include "mitkVtkOverlay3D.h" mitk::VtkOverlay3D::VtkOverlay3D() { } mitk::VtkOverlay3D::~VtkOverlay3D() { } -mitk::Overlay::Bounds mitk::VtkOverlay3D::GetBoundsOnDisplay(mitk::BaseRenderer *renderer) +mitk::Overlay::Bounds mitk::VtkOverlay3D::GetBoundsOnDisplay(mitk::BaseRenderer*) { + mitk::Overlay::Bounds bounds; + bounds.Position[0] = bounds.Position[1] = bounds.Size[0] = bounds.Size[1] = 0; } -void mitk::VtkOverlay3D::SetBoundsOnDisplay(mitk::BaseRenderer *renderer, mitk::Overlay::Bounds) +void mitk::VtkOverlay3D::SetBoundsOnDisplay(mitk::BaseRenderer*, mitk::Overlay::Bounds) { } + +void mitk::VtkOverlay3D::SetPosition3D(mitk::Point3D position3D) +{ + mitk::Point3dProperty::Pointer position3dProperty = mitk::Point3dProperty::New(position3D); + SetProperty("Pos3D", position3dProperty); +} + +void mitk::VtkOverlay3D::SetPosition3D(Point3D position3D, mitk::BaseRenderer *renderer) +{ + mitk::Point3dProperty::Pointer position3dProperty = mitk::Point3dProperty::New(position3D); + SetProperty("Pos3D", position3dProperty,renderer); +} + +mitk::Point3D mitk::VtkOverlay3D::GetPosition3D() +{ + mitk::Point3D position3D; + GetPropertyValue < mitk::Point3D > ("Pos3D", position3D); + return position3D; +} diff --git a/Core/Code/Rendering/Overlays/mitkVtkOverlay3D.h b/Core/Code/Rendering/Overlays/mitkVtkOverlay3D.h index 6a563a0e47..b0bffc4f3e 100644 --- a/Core/Code/Rendering/Overlays/mitkVtkOverlay3D.h +++ b/Core/Code/Rendering/Overlays/mitkVtkOverlay3D.h @@ -1,69 +1,69 @@ /*=================================================================== 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 VTKOVERLAY3D_H #define VTKOVERLAY3D_H #include #include #include #include "mitkVtkOverlay.h" #include "mitkBaseRenderer.h" #include namespace mitk { class MITK_CORE_EXPORT VtkOverlay3D : public VtkOverlay { public: - Overlay::Bounds GetBoundsOnDisplay(BaseRenderer *renderer); - void SetBoundsOnDisplay(BaseRenderer *renderer, Overlay::Bounds); - void SetPosition3D(Point3D position3D); void SetPosition3D(Point3D position3D, mitk::BaseRenderer* renderer); Point3D GetPosition3D(mitk::BaseRenderer* renderer); Point3D GetPosition3D(); + Overlay::Bounds GetBoundsOnDisplay(BaseRenderer*); + void SetBoundsOnDisplay(BaseRenderer*, Overlay::Bounds); + mitkClassMacro(VtkOverlay3D, VtkOverlay); protected: - vtkSmartPointer GetVtkProp(BaseRenderer *renderer) = 0; + virtual void UpdateVtkOverlay(BaseRenderer *renderer) = 0; /** \brief explicit constructor which disallows implicit conversions */ explicit VtkOverlay3D(); /** \brief virtual destructor in order to derive from this class */ virtual ~VtkOverlay3D(); private: /** \brief copy constructor */ VtkOverlay3D( const VtkOverlay3D &); /** \brief assignment operator */ VtkOverlay3D &operator=(const VtkOverlay3D &); }; } // namespace mitk #endif // OVERLAY_H diff --git a/Core/Code/Rendering/mitkBaseRenderer.cpp b/Core/Code/Rendering/mitkBaseRenderer.cpp index 8a51b76126..f36f51bc95 100644 --- a/Core/Code/Rendering/mitkBaseRenderer.cpp +++ b/Core/Code/Rendering/mitkBaseRenderer.cpp @@ -1,855 +1,859 @@ /*=================================================================== 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 "mitkBaseRenderer.h" #include "mitkMapper.h" #include "mitkResliceMethodProperty.h" #include "mitkKeyEvent.h" // Geometries #include "mitkPlaneGeometry.h" #include "mitkSlicedGeometry3D.h" // Controllers #include "mitkCameraController.h" #include "mitkSliceNavigationController.h" #include "mitkCameraRotationController.h" #include "mitkVtkInteractorCameraController.h" #ifdef MITK_USE_TD_MOUSE #include "mitkTDMouseVtkCameraController.h" #else #include "mitkCameraController.h" #endif #include "mitkVtkLayerController.h" // Events // TODO: INTERACTION_LEGACY #include "mitkEventMapper.h" #include "mitkGlobalInteraction.h" #include "mitkPositionEvent.h" #include "mitkDisplayPositionEvent.h" #include "mitkProperties.h" #include "mitkWeakPointerProperty.h" #include "mitkInteractionConst.h" #include "Overlays/mitkOverlayManager.h" // VTK #include #include #include #include #include #include #include mitk::BaseRenderer::BaseRendererMapType mitk::BaseRenderer::baseRendererMap; mitk::BaseRenderer* mitk::BaseRenderer::GetInstance(vtkRenderWindow * renWin) { for (BaseRendererMapType::iterator mapit = baseRendererMap.begin(); mapit != baseRendererMap.end(); mapit++) { if ((*mapit).first == renWin) return (*mapit).second; } return NULL; } void mitk::BaseRenderer::AddInstance(vtkRenderWindow* renWin, BaseRenderer* baseRenderer) { if (renWin == NULL || baseRenderer == NULL) return; // ensure that no BaseRenderer is managed twice mitk::BaseRenderer::RemoveInstance(renWin); baseRendererMap.insert(BaseRendererMapType::value_type(renWin, baseRenderer)); } void mitk::BaseRenderer::RemoveInstance(vtkRenderWindow* renWin) { BaseRendererMapType::iterator mapit = baseRendererMap.find(renWin); if (mapit != baseRendererMap.end()) baseRendererMap.erase(mapit); } mitk::BaseRenderer* mitk::BaseRenderer::GetByName(const std::string& name) { for (BaseRendererMapType::iterator mapit = baseRendererMap.begin(); mapit != baseRendererMap.end(); mapit++) { if ((*mapit).second->m_Name == name) return (*mapit).second; } return NULL; } vtkRenderWindow* mitk::BaseRenderer::GetRenderWindowByName(const std::string& name) { for (BaseRendererMapType::iterator mapit = baseRendererMap.begin(); mapit != baseRendererMap.end(); mapit++) { if ((*mapit).second->m_Name == name) return (*mapit).first; } return NULL; } mitk::BaseRenderer::BaseRenderer(const char* name, vtkRenderWindow * renWin, mitk::RenderingManager* rm) : m_RenderWindow(NULL), m_VtkRenderer(NULL), m_MapperID(defaultMapper), m_DataStorage(NULL), m_RenderingManager(rm), m_LastUpdateTime(0), m_CameraController( NULL), m_SliceNavigationController(NULL), m_CameraRotationController(NULL), /*m_Size(),*/ m_Focused(false), m_WorldGeometry(NULL), m_TimeSlicedWorldGeometry(NULL), m_CurrentWorldGeometry(NULL), m_CurrentWorldGeometry2D(NULL), m_DisplayGeometry( NULL), m_Slice(0), m_TimeStep(), m_CurrentWorldGeometry2DUpdateTime(), m_DisplayGeometryUpdateTime(), m_TimeStepUpdateTime(), m_WorldGeometryData( NULL), m_DisplayGeometryData(NULL), m_CurrentWorldGeometry2DData(NULL), m_WorldGeometryNode(NULL), m_DisplayGeometryNode(NULL), m_CurrentWorldGeometry2DNode( NULL), m_DisplayGeometryTransformTime(0), m_CurrentWorldGeometry2DTransformTime(0), m_Name(name), /*m_Bounds(),*/m_EmptyWorldGeometry( true), m_DepthPeelingEnabled(true), m_MaxNumberOfPeels(100), m_NumberOfVisibleLODEnabledMappers(0) { m_Bounds[0] = 0; m_Bounds[1] = 0; m_Bounds[2] = 0; m_Bounds[3] = 0; m_Bounds[4] = 0; m_Bounds[5] = 0; if (name != NULL) { m_Name = name; } else { m_Name = "unnamed renderer"; itkWarningMacro(<< "Created unnamed renderer. Bad for serialization. Please choose a name."); } if (renWin != NULL) { m_RenderWindow = renWin; m_RenderWindow->Register(NULL); } else { itkWarningMacro(<< "Created mitkBaseRenderer without vtkRenderWindow present."); } m_Size[0] = 0; m_Size[1] = 0; //instances.insert( this ); //adding this BaseRenderer to the List of all BaseRenderer // TODO: INTERACTION_LEGACY m_RenderingManager->GetGlobalInteraction()->AddFocusElement(this); m_BindDispatcherInteractor = new mitk::BindDispatcherInteractor(); WeakPointerProperty::Pointer rendererProp = WeakPointerProperty::New((itk::Object*) this); m_CurrentWorldGeometry2D = mitk::PlaneGeometry::New(); m_CurrentWorldGeometry2DData = mitk::Geometry2DData::New(); m_CurrentWorldGeometry2DData->SetGeometry2D(m_CurrentWorldGeometry2D); m_CurrentWorldGeometry2DNode = mitk::DataNode::New(); m_CurrentWorldGeometry2DNode->SetData(m_CurrentWorldGeometry2DData); m_CurrentWorldGeometry2DNode->GetPropertyList()->SetProperty("renderer", rendererProp); m_CurrentWorldGeometry2DNode->GetPropertyList()->SetProperty("layer", IntProperty::New(1000)); m_CurrentWorldGeometry2DNode->SetProperty("reslice.thickslices", mitk::ResliceMethodProperty::New()); m_CurrentWorldGeometry2DNode->SetProperty("reslice.thickslices.num", mitk::IntProperty::New(1)); m_CurrentWorldGeometry2DTransformTime = m_CurrentWorldGeometry2DNode->GetVtkTransform()->GetMTime(); m_DisplayGeometry = mitk::DisplayGeometry::New(); m_DisplayGeometry->SetWorldGeometry(m_CurrentWorldGeometry2D); m_DisplayGeometryData = mitk::Geometry2DData::New(); m_DisplayGeometryData->SetGeometry2D(m_DisplayGeometry); m_DisplayGeometryNode = mitk::DataNode::New(); m_DisplayGeometryNode->SetData(m_DisplayGeometryData); m_DisplayGeometryNode->GetPropertyList()->SetProperty("renderer", rendererProp); m_DisplayGeometryTransformTime = m_DisplayGeometryNode->GetVtkTransform()->GetMTime(); mitk::SliceNavigationController::Pointer sliceNavigationController = mitk::SliceNavigationController::New("navigation"); sliceNavigationController->SetRenderer(this); sliceNavigationController->ConnectGeometrySliceEvent(this); sliceNavigationController->ConnectGeometryUpdateEvent(this); sliceNavigationController->ConnectGeometryTimeEvent(this, false); m_SliceNavigationController = sliceNavigationController; m_CameraRotationController = mitk::CameraRotationController::New(); m_CameraRotationController->SetRenderWindow(m_RenderWindow); m_CameraRotationController->AcquireCamera(); //if TD Mouse Interaction is activated, then call TDMouseVtkCameraController instead of VtkInteractorCameraController #ifdef MITK_USE_TD_MOUSE m_CameraController = mitk::TDMouseVtkCameraController::New(); #else m_CameraController = mitk::CameraController::New(NULL); #endif m_VtkRenderer = vtkRenderer::New(); if (mitk::VtkLayerController::GetInstance(m_RenderWindow) == NULL) { mitk::VtkLayerController::AddInstance(m_RenderWindow, m_VtkRenderer); mitk::VtkLayerController::GetInstance(m_RenderWindow)->InsertSceneRenderer(m_VtkRenderer); } else mitk::VtkLayerController::GetInstance(m_RenderWindow)->InsertSceneRenderer(m_VtkRenderer); } mitk::BaseRenderer::~BaseRenderer() { if (m_VtkRenderer != NULL) { m_VtkRenderer->Delete(); m_VtkRenderer = NULL; } if (m_CameraController.IsNotNull()) m_CameraController->SetRenderer(NULL); m_RenderingManager->GetGlobalInteraction()->RemoveFocusElement(this); mitk::VtkLayerController::RemoveInstance(m_RenderWindow); RemoveAllLocalStorages(); m_DataStorage = NULL; if (m_BindDispatcherInteractor != NULL) { delete m_BindDispatcherInteractor; } if (m_RenderWindow != NULL) { m_RenderWindow->Delete(); m_RenderWindow = NULL; } } void mitk::BaseRenderer::RemoveAllLocalStorages() { this->InvokeEvent(mitk::BaseRenderer::RendererResetEvent()); std::list::iterator it; for (it = m_RegisteredLocalStorageHandlers.begin(); it != m_RegisteredLocalStorageHandlers.end(); it++) (*it)->ClearLocalStorage(this, false); m_RegisteredLocalStorageHandlers.clear(); } void mitk::BaseRenderer::RegisterLocalStorageHandler(mitk::BaseLocalStorageHandler *lsh) { m_RegisteredLocalStorageHandlers.push_back(lsh); } mitk::Dispatcher::Pointer mitk::BaseRenderer::GetDispatcher() const { return m_BindDispatcherInteractor->GetDispatcher(); } mitk::Point3D mitk::BaseRenderer::Map2DRendererPositionTo3DWorldPosition(Point2D* mousePosition) const { Point2D p_mm; Point3D position; if (m_MapperID == 1) { GetDisplayGeometry()->ULDisplayToDisplay(*mousePosition, *mousePosition); GetDisplayGeometry()->DisplayToWorld(*mousePosition, p_mm); GetDisplayGeometry()->Map(p_mm, position); } else if (m_MapperID == 2) { GetDisplayGeometry()->ULDisplayToDisplay(*mousePosition, *mousePosition); PickWorldPoint(*mousePosition, position); } return position; } void mitk::BaseRenderer::UnregisterLocalStorageHandler(mitk::BaseLocalStorageHandler *lsh) { m_RegisteredLocalStorageHandlers.remove(lsh); } void mitk::BaseRenderer::SetDataStorage(DataStorage* storage) { if (storage != NULL) { m_DataStorage = storage; m_BindDispatcherInteractor->SetDataStorage(m_DataStorage); this->Modified(); } } const mitk::BaseRenderer::MapperSlotId mitk::BaseRenderer::defaultMapper = 1; void mitk::BaseRenderer::Paint() { } void mitk::BaseRenderer::Initialize() { } void mitk::BaseRenderer::Resize(int w, int h) { m_Size[0] = w; m_Size[1] = h; if (m_CameraController) m_CameraController->Resize(w, h); //(formerly problematic on windows: vtkSizeBug) GetDisplayGeometry()->SetSizeInDisplayUnits(w, h); } void mitk::BaseRenderer::InitRenderer(vtkRenderWindow* renderwindow) { if (m_RenderWindow != NULL) { m_RenderWindow->Delete(); } m_RenderWindow = renderwindow; if (m_RenderWindow != NULL) { m_RenderWindow->Register(NULL); } RemoveAllLocalStorages(); if (m_CameraController.IsNotNull()) { m_CameraController->SetRenderer(this); } //BUG (#1551) added settings for depth peeling m_RenderWindow->SetAlphaBitPlanes(1); m_VtkRenderer->SetUseDepthPeeling(m_DepthPeelingEnabled); m_VtkRenderer->SetMaximumNumberOfPeels(m_MaxNumberOfPeels); m_VtkRenderer->SetOcclusionRatio(0.1); } void mitk::BaseRenderer::InitSize(int w, int h) { m_Size[0] = w; m_Size[1] = h; GetDisplayGeometry()->SetSizeInDisplayUnits(w, h, false); GetDisplayGeometry()->Fit(); } void mitk::BaseRenderer::SetSlice(unsigned int slice) { if (m_Slice != slice) { m_Slice = slice; if (m_TimeSlicedWorldGeometry.IsNotNull()) { SlicedGeometry3D* slicedWorldGeometry = dynamic_cast(m_TimeSlicedWorldGeometry->GetGeometry3D(m_TimeStep)); if (slicedWorldGeometry != NULL) { if (m_Slice >= slicedWorldGeometry->GetSlices()) m_Slice = slicedWorldGeometry->GetSlices() - 1; SetCurrentWorldGeometry2D(slicedWorldGeometry->GetGeometry2D(m_Slice)); SetCurrentWorldGeometry(slicedWorldGeometry); } } else Modified(); } } void mitk::BaseRenderer::SetOverlayManager(itk::SmartPointer overlayManager) { + if(overlayManager.IsNotNull()) + { this->m_OverlayManager = overlayManager; + this->m_OverlayManager->AddBaseRenderer(this); + } } itk::SmartPointer mitk::BaseRenderer::GetOverlayManager() { return m_OverlayManager; } void mitk::BaseRenderer::SetTimeStep(unsigned int timeStep) { if (m_TimeStep != timeStep) { m_TimeStep = timeStep; m_TimeStepUpdateTime.Modified(); if (m_TimeSlicedWorldGeometry.IsNotNull()) { if (m_TimeStep >= m_TimeSlicedWorldGeometry->GetTimeSteps()) m_TimeStep = m_TimeSlicedWorldGeometry->GetTimeSteps() - 1; SlicedGeometry3D* slicedWorldGeometry = dynamic_cast(m_TimeSlicedWorldGeometry->GetGeometry3D(m_TimeStep)); if (slicedWorldGeometry != NULL) { SetCurrentWorldGeometry2D(slicedWorldGeometry->GetGeometry2D(m_Slice)); SetCurrentWorldGeometry(slicedWorldGeometry); } } else Modified(); } } int mitk::BaseRenderer::GetTimeStep(const mitk::BaseData* data) const { if ((data == NULL) || (data->IsInitialized() == false)) { return -1; } return data->GetTimeSlicedGeometry()->MSToTimeStep(GetTime()); } mitk::ScalarType mitk::BaseRenderer::GetTime() const { if (m_TimeSlicedWorldGeometry.IsNull()) { return 0; } else { ScalarType timeInMS = m_TimeSlicedWorldGeometry->TimeStepToMS(GetTimeStep()); if (timeInMS == ScalarTypeNumericTraits::NonpositiveMin()) return 0; else return timeInMS; } } void mitk::BaseRenderer::SetWorldGeometry(mitk::Geometry3D* geometry) { itkDebugMacro("setting WorldGeometry to " << geometry); if (m_WorldGeometry != geometry) { if (geometry->GetBoundingBox()->GetDiagonalLength2() == 0) return; m_WorldGeometry = geometry; m_TimeSlicedWorldGeometry = dynamic_cast(geometry); SlicedGeometry3D* slicedWorldGeometry; if (m_TimeSlicedWorldGeometry.IsNotNull()) { itkDebugMacro("setting TimeSlicedWorldGeometry to " << m_TimeSlicedWorldGeometry); if (m_TimeStep >= m_TimeSlicedWorldGeometry->GetTimeSteps()) m_TimeStep = m_TimeSlicedWorldGeometry->GetTimeSteps() - 1; slicedWorldGeometry = dynamic_cast(m_TimeSlicedWorldGeometry->GetGeometry3D(m_TimeStep)); } else { slicedWorldGeometry = dynamic_cast(geometry); } Geometry2D::Pointer geometry2d; if (slicedWorldGeometry != NULL) { if (m_Slice >= slicedWorldGeometry->GetSlices() && (m_Slice != 0)) m_Slice = slicedWorldGeometry->GetSlices() - 1; geometry2d = slicedWorldGeometry->GetGeometry2D(m_Slice); if (geometry2d.IsNull()) { PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New(); plane->InitializeStandardPlane(slicedWorldGeometry); geometry2d = plane; } SetCurrentWorldGeometry(slicedWorldGeometry); } else { geometry2d = dynamic_cast(geometry); if (geometry2d.IsNull()) { PlaneGeometry::Pointer plane = PlaneGeometry::New(); plane->InitializeStandardPlane(geometry); geometry2d = plane; } SetCurrentWorldGeometry(geometry); } SetCurrentWorldGeometry2D(geometry2d); // calls Modified() } if (m_CurrentWorldGeometry2D.IsNull()) itkWarningMacro("m_CurrentWorldGeometry2D is NULL"); } void mitk::BaseRenderer::SetDisplayGeometry(mitk::DisplayGeometry* geometry2d) { itkDebugMacro("setting DisplayGeometry to " << geometry2d); if (m_DisplayGeometry != geometry2d) { m_DisplayGeometry = geometry2d; m_DisplayGeometryData->SetGeometry2D(m_DisplayGeometry); m_DisplayGeometryUpdateTime.Modified(); Modified(); } } void mitk::BaseRenderer::SetCurrentWorldGeometry2D(mitk::Geometry2D* geometry2d) { if (m_CurrentWorldGeometry2D != geometry2d) { m_CurrentWorldGeometry2D = geometry2d; m_CurrentWorldGeometry2DData->SetGeometry2D(m_CurrentWorldGeometry2D); m_DisplayGeometry->SetWorldGeometry(m_CurrentWorldGeometry2D); m_CurrentWorldGeometry2DUpdateTime.Modified(); Modified(); } } void mitk::BaseRenderer::SendUpdateSlice() { m_DisplayGeometryUpdateTime.Modified(); m_CurrentWorldGeometry2DUpdateTime.Modified(); } void mitk::BaseRenderer::SetCurrentWorldGeometry(mitk::Geometry3D* geometry) { m_CurrentWorldGeometry = geometry; if (geometry == NULL) { m_Bounds[0] = 0; m_Bounds[1] = 0; m_Bounds[2] = 0; m_Bounds[3] = 0; m_Bounds[4] = 0; m_Bounds[5] = 0; m_EmptyWorldGeometry = true; return; } BoundingBox::Pointer boundingBox = m_CurrentWorldGeometry->CalculateBoundingBoxRelativeToTransform(NULL); const BoundingBox::BoundsArrayType& worldBounds = boundingBox->GetBounds(); m_Bounds[0] = worldBounds[0]; m_Bounds[1] = worldBounds[1]; m_Bounds[2] = worldBounds[2]; m_Bounds[3] = worldBounds[3]; m_Bounds[4] = worldBounds[4]; m_Bounds[5] = worldBounds[5]; if (boundingBox->GetDiagonalLength2() <= mitk::eps) m_EmptyWorldGeometry = true; else m_EmptyWorldGeometry = false; } void mitk::BaseRenderer::AddAllOverlays() { if(m_OverlayManager.IsNotNull()) { m_OverlayManager->UpdateOverlays(this); } } void mitk::BaseRenderer::SetGeometry(const itk::EventObject & geometrySendEvent) { const SliceNavigationController::GeometrySendEvent* sendEvent = dynamic_cast(&geometrySendEvent); assert(sendEvent!=NULL); SetWorldGeometry(sendEvent->GetTimeSlicedGeometry()); } void mitk::BaseRenderer::UpdateGeometry(const itk::EventObject & geometryUpdateEvent) { const SliceNavigationController::GeometryUpdateEvent* updateEvent = dynamic_cast(&geometryUpdateEvent); if (updateEvent == NULL) return; if (m_CurrentWorldGeometry.IsNotNull()) { SlicedGeometry3D* slicedWorldGeometry = dynamic_cast(m_CurrentWorldGeometry.GetPointer()); if (slicedWorldGeometry) { Geometry2D* geometry2D = slicedWorldGeometry->GetGeometry2D(m_Slice); SetCurrentWorldGeometry2D(geometry2D); // calls Modified() } } } void mitk::BaseRenderer::SetGeometrySlice(const itk::EventObject & geometrySliceEvent) { const SliceNavigationController::GeometrySliceEvent* sliceEvent = dynamic_cast(&geometrySliceEvent); assert(sliceEvent!=NULL); SetSlice(sliceEvent->GetPos()); } void mitk::BaseRenderer::SetGeometryTime(const itk::EventObject & geometryTimeEvent) { const SliceNavigationController::GeometryTimeEvent * timeEvent = dynamic_cast(&geometryTimeEvent); assert(timeEvent!=NULL); SetTimeStep(timeEvent->GetPos()); } const double* mitk::BaseRenderer::GetBounds() const { return m_Bounds; } void mitk::BaseRenderer::MousePressEvent(mitk::MouseEvent *me) { //set the Focus on the renderer /*bool success =*/m_RenderingManager->GetGlobalInteraction()->SetFocus(this); /* if (! success) mitk::StatusBar::GetInstance()->DisplayText("Warning! from mitkBaseRenderer.cpp: Couldn't focus this BaseRenderer!"); */ //if (m_CameraController) //{ // if(me->GetButtonState()!=512) // provisorisch: Ctrl nicht durchlassen. Bald wird aus m_CameraController eine StateMachine // m_CameraController->MousePressEvent(me); //} if (m_MapperID == 1) { Point2D p(me->GetDisplayPosition()); Point2D p_mm; Point3D position; GetDisplayGeometry()->ULDisplayToDisplay(p, p); GetDisplayGeometry()->DisplayToWorld(p, p_mm); GetDisplayGeometry()->Map(p_mm, position); mitk::PositionEvent event(this, me->GetType(), me->GetButton(), me->GetButtonState(), mitk::Key_unknown, p, position); mitk::EventMapper::MapEvent(&event, m_RenderingManager->GetGlobalInteraction()); } else if (m_MapperID > 1) //==2 for 3D and ==5 for stencil { Point2D p(me->GetDisplayPosition()); GetDisplayGeometry()->ULDisplayToDisplay(p, p); me->SetDisplayPosition(p); mitk::EventMapper::MapEvent(me, m_RenderingManager->GetGlobalInteraction()); } } void mitk::BaseRenderer::MouseReleaseEvent(mitk::MouseEvent *me) { //if (m_CameraController) //{ // if(me->GetButtonState()!=512) // provisorisch: Ctrl nicht durchlassen. Bald wird aus m_CameraController eine StateMachine // m_CameraController->MouseReleaseEvent(me); //} if (m_MapperID == 1) { Point2D p(me->GetDisplayPosition()); Point2D p_mm; Point3D position; GetDisplayGeometry()->ULDisplayToDisplay(p, p); GetDisplayGeometry()->DisplayToWorld(p, p_mm); GetDisplayGeometry()->Map(p_mm, position); mitk::PositionEvent event(this, me->GetType(), me->GetButton(), me->GetButtonState(), mitk::Key_unknown, p, position); mitk::EventMapper::MapEvent(&event, m_RenderingManager->GetGlobalInteraction()); } else if (m_MapperID == 2) { Point2D p(me->GetDisplayPosition()); GetDisplayGeometry()->ULDisplayToDisplay(p, p); me->SetDisplayPosition(p); mitk::EventMapper::MapEvent(me, m_RenderingManager->GetGlobalInteraction()); } } void mitk::BaseRenderer::MouseMoveEvent(mitk::MouseEvent *me) { //if (m_CameraController) //{ // if((me->GetButtonState()<=512) || (me->GetButtonState()>=516))// provisorisch: Ctrl nicht durchlassen. Bald wird aus m_CameraController eine StateMachine // m_CameraController->MouseMoveEvent(me); //} if (m_MapperID == 1) { Point2D p(me->GetDisplayPosition()); Point2D p_mm; Point3D position; GetDisplayGeometry()->ULDisplayToDisplay(p, p); GetDisplayGeometry()->DisplayToWorld(p, p_mm); GetDisplayGeometry()->Map(p_mm, position); mitk::PositionEvent event(this, me->GetType(), me->GetButton(), me->GetButtonState(), mitk::Key_unknown, p, position); mitk::EventMapper::MapEvent(&event, m_RenderingManager->GetGlobalInteraction()); } else if (m_MapperID == 2) { Point2D p(me->GetDisplayPosition()); GetDisplayGeometry()->ULDisplayToDisplay(p, p); me->SetDisplayPosition(p); mitk::EventMapper::MapEvent(me, m_RenderingManager->GetGlobalInteraction()); } } void mitk::BaseRenderer::PickWorldPoint(const mitk::Point2D& displayPoint, mitk::Point3D& worldPoint) const { mitk::Point2D worldPoint2D; GetDisplayGeometry()->DisplayToWorld(displayPoint, worldPoint2D); GetDisplayGeometry()->Map(worldPoint2D, worldPoint); } void mitk::BaseRenderer::WheelEvent(mitk::WheelEvent * we) { if (m_MapperID == 1) { Point2D p(we->GetDisplayPosition()); Point2D p_mm; Point3D position; GetDisplayGeometry()->ULDisplayToDisplay(p, p); GetDisplayGeometry()->DisplayToWorld(p, p_mm); GetDisplayGeometry()->Map(p_mm, position); mitk::PositionEvent event(this, we->GetType(), we->GetButton(), we->GetButtonState(), mitk::Key_unknown, p, position); mitk::EventMapper::MapEvent(we, m_RenderingManager->GetGlobalInteraction()); mitk::EventMapper::MapEvent(&event, m_RenderingManager->GetGlobalInteraction()); } else if (m_MapperID == 2) { Point2D p(we->GetDisplayPosition()); GetDisplayGeometry()->ULDisplayToDisplay(p, p); we->SetDisplayPosition(p); mitk::EventMapper::MapEvent(we, m_RenderingManager->GetGlobalInteraction()); } } void mitk::BaseRenderer::KeyPressEvent(mitk::KeyEvent *ke) { if (m_MapperID == 1) { Point2D p(ke->GetDisplayPosition()); Point2D p_mm; Point3D position; GetDisplayGeometry()->ULDisplayToDisplay(p, p); GetDisplayGeometry()->DisplayToWorld(p, p_mm); GetDisplayGeometry()->Map(p_mm, position); mitk::KeyEvent event(this, ke->GetType(), ke->GetButton(), ke->GetButtonState(), ke->GetKey(), ke->GetText(), p); mitk::EventMapper::MapEvent(&event, m_RenderingManager->GetGlobalInteraction()); } else if (m_MapperID == 2) { Point2D p(ke->GetDisplayPosition()); GetDisplayGeometry()->ULDisplayToDisplay(p, p); ke->SetDisplayPosition(p); mitk::EventMapper::MapEvent(ke, m_RenderingManager->GetGlobalInteraction()); } } void mitk::BaseRenderer::DrawOverlayMouse(mitk::Point2D& itkNotUsed(p2d)) { MITK_INFO<<"BaseRenderer::DrawOverlayMouse()- should be inconcret implementation OpenGLRenderer."<RequestUpdate(this->m_RenderWindow); } void mitk::BaseRenderer::ForceImmediateUpdate() { m_RenderingManager->ForceImmediateUpdate(this->m_RenderWindow); } unsigned int mitk::BaseRenderer::GetNumberOfVisibleLODEnabledMappers() const { return m_NumberOfVisibleLODEnabledMappers; } mitk::RenderingManager* mitk::BaseRenderer::GetRenderingManager() const { return m_RenderingManager.GetPointer(); } /*! Sets the new Navigation controller */ void mitk::BaseRenderer::SetSliceNavigationController(mitk::SliceNavigationController *SlicenavigationController) { if (SlicenavigationController == NULL) return; //disconnect old from globalinteraction m_RenderingManager->GetGlobalInteraction()->RemoveListener(SlicenavigationController); //copy worldgeometry SlicenavigationController->SetInputWorldGeometry(SlicenavigationController->GetCreatedWorldGeometry()); SlicenavigationController->Update(); //set new m_SliceNavigationController = SlicenavigationController; m_SliceNavigationController->SetRenderer(this); if (m_SliceNavigationController.IsNotNull()) { m_SliceNavigationController->ConnectGeometrySliceEvent(this); m_SliceNavigationController->ConnectGeometryUpdateEvent(this); m_SliceNavigationController->ConnectGeometryTimeEvent(this, false); } } /*! Sets the new camera controller and deletes the vtkRenderWindowInteractor in case of the VTKInteractorCameraController */ void mitk::BaseRenderer::SetCameraController(CameraController* cameraController) { mitk::VtkInteractorCameraController::Pointer vtkInteractorCameraController = dynamic_cast(cameraController); if (vtkInteractorCameraController.IsNotNull()) MITK_INFO<<"!!!WARNING!!!: RenderWindow interaction events are no longer handled via CameraController (See Bug #954)."<SetRenderer(NULL); m_CameraController = NULL; m_CameraController = cameraController; m_CameraController->SetRenderer(this); } void mitk::BaseRenderer::PrintSelf(std::ostream& os, itk::Indent indent) const { os << indent << " MapperID: " << m_MapperID << std::endl; os << indent << " Slice: " << m_Slice << std::endl; os << indent << " TimeStep: " << m_TimeStep << std::endl; os << indent << " WorldGeometry: "; if (m_WorldGeometry.IsNull()) os << "NULL" << std::endl; else m_WorldGeometry->Print(os, indent); os << indent << " CurrentWorldGeometry2D: "; if (m_CurrentWorldGeometry2D.IsNull()) os << "NULL" << std::endl; else m_CurrentWorldGeometry2D->Print(os, indent); os << indent << " CurrentWorldGeometry2DUpdateTime: " << m_CurrentWorldGeometry2DUpdateTime << std::endl; os << indent << " CurrentWorldGeometry2DTransformTime: " << m_CurrentWorldGeometry2DTransformTime << std::endl; os << indent << " DisplayGeometry: "; if (m_DisplayGeometry.IsNull()) os << "NULL" << std::endl; else m_DisplayGeometry->Print(os, indent); os << indent << " DisplayGeometryTransformTime: " << m_DisplayGeometryTransformTime << std::endl; Superclass::PrintSelf(os, indent); } void mitk::BaseRenderer::SetDepthPeelingEnabled(bool enabled) { m_DepthPeelingEnabled = enabled; m_VtkRenderer->SetUseDepthPeeling(enabled); } void mitk::BaseRenderer::SetMaxNumberOfPeels(int maxNumber) { m_MaxNumberOfPeels = maxNumber; m_VtkRenderer->SetMaximumNumberOfPeels(maxNumber); }