diff --git a/Modules/Overlays/files.cmake b/Modules/Overlays/files.cmake index 4f128aa132..f561d168c0 100644 --- a/Modules/Overlays/files.cmake +++ b/Modules/Overlays/files.cmake @@ -1,13 +1,14 @@ set(H_FILES ) set(CPP_FILES mitkTextOverlay2D.cpp mitkTextOverlay3D.cpp mitkLabelOverlay3D.cpp + mitkColorBarOverlay.cpp mitkOverlay2DLayouter.cpp mitkScaleLegendOverlay.cpp mitkLogoOverlay.cpp mitkVtkLogoRepresentation.cxx ) diff --git a/Modules/Overlays/mitkColorBarOverlay.cpp b/Modules/Overlays/mitkColorBarOverlay.cpp new file mode 100644 index 0000000000..7e12808596 --- /dev/null +++ b/Modules/Overlays/mitkColorBarOverlay.cpp @@ -0,0 +1,183 @@ +/*=================================================================== + +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 "mitkColorBarOverlay.h" +#include "mitkLookupTable.h" +#include "mitkLookupTableProperty.h" +#include + +mitk::ColorBarOverlay::ColorBarOverlay() +{ + SetDrawAnnotations(true); + + SetDrawTickLabels(true); + + SetOrientationToVertical(); + + SetMaxNumberOfColors(100); + SetNumberOfLabels(4); + + SetAnnotationTextScaling(false); + + SetLookupTable(NULL); +} + + +mitk::ColorBarOverlay::~ColorBarOverlay() +{ +} + +mitk::ColorBarOverlay::LocalStorage::~LocalStorage() +{ +} + +mitk::ColorBarOverlay::LocalStorage::LocalStorage() +{ + m_ScalarBarActor = vtkSmartPointer::New(); +} + +void mitk::ColorBarOverlay::UpdateVtkOverlay(mitk::BaseRenderer *renderer) +{ + LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); + + if(ls->IsGenerateDataRequired(renderer,this)) + { + ls->m_ScalarBarActor->SetDrawAnnotations(this->GetDrawAnnotations()); + ls->m_ScalarBarActor->SetLookupTable(this->GetLookupTable()); + ls->m_ScalarBarActor->SetOrientation(this->GetOrientation()); + ls->m_ScalarBarActor->SetDrawTickLabels(this->GetDrawTickLabels()); + ls->m_ScalarBarActor->SetMaximumNumberOfColors(this->GetMaxNumberOfColors()); + ls->m_ScalarBarActor->SetNumberOfLabels(this->GetNumberOfLabels()); + ls->m_ScalarBarActor->SetAnnotationTextScaling(this->GetAnnotationTextScaling()); + //manually set position so there is no overlap with mitk logo in 3d renderwindow + if (this->GetOrientation()==1) + { + ls->m_ScalarBarActor->SetPosition(0.80,0.15); + ls->m_ScalarBarActor->SetWidth(0.15); + ls->m_ScalarBarActor->SetHeight(0.85); + }else + { + ls->m_ScalarBarActor->SetPosition(0.03,0.03); + ls->m_ScalarBarActor->SetWidth(0.8); + ls->m_ScalarBarActor->SetHeight(0.15); + } + } + +} + +vtkProp* mitk::ColorBarOverlay::GetVtkProp(BaseRenderer *renderer) const +{ + LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); + return ls->m_ScalarBarActor; +} + +void mitk::ColorBarOverlay::SetDrawAnnotations(bool annotations) +{ + SetBoolProperty("ColorBarOverlay.DrawAnnotations", annotations); +} + +bool mitk::ColorBarOverlay::GetDrawAnnotations() const +{ + bool annotations; + GetPropertyList()->GetBoolProperty("ColorBarOverlay.DrawAnnotations", annotations); + return annotations; +} + +void mitk::ColorBarOverlay::SetLookupTable(vtkSmartPointer table) +{ + mitk::LookupTable::Pointer lut = mitk::LookupTable::New(); + mitk::LookupTableProperty::Pointer prop = mitk::LookupTableProperty::New(lut); + lut->SetVtkLookupTable(table); + prop->SetLookupTable(lut); + SetProperty("ColorBarOverlay.LookupTable", prop.GetPointer()); +} + +vtkSmartPointer mitk::ColorBarOverlay::GetLookupTable() const +{ + mitk::LookupTable::Pointer lut = mitk::LookupTable::New(); + lut = dynamic_cast(GetPropertyList()->GetProperty("ColorBarOverlay.LookupTable"))->GetLookupTable(); + return lut->GetVtkLookupTable(); +} + +void mitk::ColorBarOverlay::SetOrientation(int orientation) +{ + SetIntProperty("ColorBarOverlay.Orientation", orientation); +} + +int mitk::ColorBarOverlay::GetOrientation() const +{ + int orientation; + GetPropertyList()->GetIntProperty("ColorBarOverlay.Orientation", orientation); + return orientation; +} + +void mitk::ColorBarOverlay::SetDrawTickLabels(bool ticks) +{ + SetBoolProperty("ColorBarOverlay.DrawTicks", ticks); +} + +bool mitk::ColorBarOverlay::GetDrawTickLabels() const +{ + bool ticks; + GetPropertyList()->GetBoolProperty("ColorBarOverlay.DrawTicks", ticks); + return ticks; +} + +void mitk::ColorBarOverlay::SetOrientationToHorizontal() +{ + SetOrientation(0); +} + +void mitk::ColorBarOverlay::SetOrientationToVertical() +{ + SetOrientation(1); +} + +void mitk::ColorBarOverlay::SetMaxNumberOfColors(int numberOfColors) +{ + SetIntProperty("ColorBarOverlay.MaximumNumberOfColors", numberOfColors); +} + +int mitk::ColorBarOverlay::GetMaxNumberOfColors() const +{ + int numberOfColors; + GetPropertyList()->GetIntProperty("ColorBarOverlay.MaximumNumberOfColors", numberOfColors); + return numberOfColors; +} + +void mitk::ColorBarOverlay::SetNumberOfLabels(int numberOfLabels) +{ + SetIntProperty("ColorBarOverlay.NumberOfLabels", numberOfLabels); +} + +int mitk::ColorBarOverlay::GetNumberOfLabels() const +{ + int numberOfLabels; + GetPropertyList()->GetIntProperty("ColorBarOverlay.NumberOfLabels", numberOfLabels); + return numberOfLabels; +} + +void mitk::ColorBarOverlay::SetAnnotationTextScaling(bool scale) +{ + SetBoolProperty("ColorBarOverlay.ScaleAnnotationText", scale); +} + +bool mitk::ColorBarOverlay::GetAnnotationTextScaling() const +{ + bool scale; + GetPropertyList()->GetBoolProperty("ColorBarOverlay.ScaleAnnotationText", scale); + return scale; +} diff --git a/Modules/Overlays/mitkColorBarOverlay.h b/Modules/Overlays/mitkColorBarOverlay.h new file mode 100644 index 0000000000..e7a4dfc4d3 --- /dev/null +++ b/Modules/Overlays/mitkColorBarOverlay.h @@ -0,0 +1,101 @@ +/*=================================================================== + + 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 COLORBAROVERLAY_H +#define COLORBAROVERLAY_H + +#include +#include +#include +#include +#include "MitkCoreExports.h" + +class vtkScalarBarActor; + +namespace mitk { + +/** \brief Displays configurable scales on the renderwindow. The scale is determined by the image spacing. */ +class MITK_CORE_EXPORT ColorBarOverlay : public mitk::VtkOverlay { +public: + + class LocalStorage : public mitk::Overlay::BaseLocalStorage + { + public: + /** \brief Actor of a 2D render window. */ + vtkSmartPointer m_ScalarBarActor; + + /** \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(ColorBarOverlay, mitk::VtkOverlay); + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + void SetDrawAnnotations(bool annotations); + bool GetDrawAnnotations() const; + + void SetOrientationToHorizontal(); + void SetOrientationToVertical(); + void SetOrientation(int orientation); + int GetOrientation() const; + + void SetMaxNumberOfColors(int numberOfColors); + int GetMaxNumberOfColors() const; + + void SetNumberOfLabels(int numberOfLabels); + int GetNumberOfLabels() const; + + void SetLookupTable(vtkSmartPointer table); + vtkSmartPointer GetLookupTable() const; + + void SetDrawTickLabels(bool ticks); + bool GetDrawTickLabels() const; + + void SetAnnotationTextScaling(bool scale); + bool GetAnnotationTextScaling() const; + +protected: + + /** \brief The LocalStorageHandler holds all LocalStorages for the render windows. */ + mutable mitk::LocalStorageHandler m_LSH; + + virtual vtkProp* GetVtkProp(BaseRenderer *renderer) const; + virtual void UpdateVtkOverlay(BaseRenderer *renderer); + + /** \brief explicit constructor which disallows implicit conversions */ + explicit ColorBarOverlay(); + + /** \brief virtual destructor in order to derive from this class */ + virtual ~ColorBarOverlay(); + +private: + + /** \brief copy constructor */ + ColorBarOverlay( const ColorBarOverlay &); + + /** \brief assignment operator */ + ColorBarOverlay &operator=(const ColorBarOverlay &); + +}; + +} // namespace mitk +#endif // COLORBAROVERLAY_H