diff --git a/Modules/Overlays/files.cmake b/Modules/Overlays/files.cmake index 992123387c..4f128aa132 100644 --- a/Modules/Overlays/files.cmake +++ b/Modules/Overlays/files.cmake @@ -1,11 +1,13 @@ set(H_FILES ) set(CPP_FILES mitkTextOverlay2D.cpp mitkTextOverlay3D.cpp mitkLabelOverlay3D.cpp mitkOverlay2DLayouter.cpp mitkScaleLegendOverlay.cpp + mitkLogoOverlay.cpp + mitkVtkLogoRepresentation.cxx ) diff --git a/Modules/Overlays/mitkLogoOverlay.cpp b/Modules/Overlays/mitkLogoOverlay.cpp new file mode 100644 index 0000000000..d015c5bc41 --- /dev/null +++ b/Modules/Overlays/mitkLogoOverlay.cpp @@ -0,0 +1,180 @@ +/*=================================================================== + +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 "mitkLogoOverlay.h" +#include +#include "vtkUnicodeString.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +mitk::LogoOverlay::LogoOverlay() +{ + m_readerFactory = vtkSmartPointer::New(); + mitk::Point2D offset; + offset.Fill(0.03); + SetOffsetVector(offset); + SetRelativeSize(0.2); + SetCornerPosition(4); +} + + +mitk::LogoOverlay::~LogoOverlay() +{ +} + +mitk::LogoOverlay::LocalStorage::~LocalStorage() +{ +} + +mitk::LogoOverlay::LocalStorage::LocalStorage() +{ + vtkImageImport* VtkImageImport = vtkImageImport::New(); + VtkImageImport->SetDataScalarTypeToUnsignedChar(); + VtkImageImport->SetNumberOfScalarComponents(mbiLogo_NumberOfScalars); + VtkImageImport->SetWholeExtent(0,mbiLogo_Width-1,0,mbiLogo_Height-1,0,1-1); + VtkImageImport->SetDataExtentToWholeExtent(); + + char * ImageData; + // flip mbi logo around y axis and change color order + ImageData = new char[mbiLogo_Height*mbiLogo_Width*mbiLogo_NumberOfScalars]; + + unsigned int column, row; + char * dest = ImageData; + char * source = (char*) &mbiLogo_Data[0];; + char r, g, b, a; + for (column = 0; column < mbiLogo_Height; column++) + for (row = 0; row < mbiLogo_Width; row++) + { //change r with b + b = *source++; + g = *source++; + r = *source++; + a = *source++; + + *dest++ = r; + *dest++ = g; + *dest++ = b; + *dest++ = a; + } + + VtkImageImport->SetImportVoidPointer(ImageData); + VtkImageImport->Modified(); + VtkImageImport->Update(); + m_LogoImage = VtkImageImport->GetOutput(); + + m_LogoRep = vtkSmartPointer::New(); + m_LogoWidget = vtkSmartPointer::New(); + m_LogoWidget->SetRepresentation(m_LogoRep); +} + +void mitk::LogoOverlay::UpdateVtkOverlay(mitk::BaseRenderer *renderer) +{ + LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); + if(ls->IsGenerateDataRequired(renderer,this)) + { + + ls->m_LogoRep->SetImage(ls->m_LogoImage); + ls->m_LogoRep->SetDragable(false); + ls->m_LogoRep->SetMoving(false); + ls->m_LogoRep->SetPickable(false); + ls->m_LogoRep->SetShowBorder(true); + ls->m_LogoRep->SetRenderer(renderer->GetVtkRenderer()); + float size = GetRelativeSize(renderer); + ls->m_LogoRep->SetPosition2(size,size); + int corner = GetCornerPosition(renderer); + ls->m_LogoRep->SetCornerPosition(corner); + mitk::Point2D offset = GetOffsetVector(renderer); + ls->m_LogoRep->SetPosition(offset[0],offset[1]); + float opacity = 1.0; + GetOpacity(opacity,renderer); + ls->m_LogoRep->GetImageProperty()->SetOpacity(opacity); + ls->m_LogoRep->BuildRepresentation(); + ls->UpdateGenerateDataTime(); + } + +} + +void mitk::LogoOverlay::SetLogoImagePath(std::string path) +{ + SetStringProperty("Overlay.LogoImagePath", path.c_str()); + Modified(); +} + +std::string mitk::LogoOverlay::GetLogoImagePath() const +{ + std::string path; + GetPropertyList()->GetStringProperty("Overlay.LogoImagePath", path); + return path; +} + +void mitk::LogoOverlay::SetOffsetVector(const Point2D& OffsetVector, mitk::BaseRenderer *renderer) +{ + mitk::Point2dProperty::Pointer OffsetVectorProperty = mitk::Point2dProperty::New(OffsetVector); + SetProperty("Overlay.OffsetVector", OffsetVectorProperty.GetPointer(),renderer); + Modified(); +} + +mitk::Point2D mitk::LogoOverlay::GetOffsetVector(mitk::BaseRenderer *renderer) const +{ + mitk::Point2D OffsetVector; + OffsetVector.Fill(0); + GetPropertyValue("Overlay.OffsetVector", OffsetVector, renderer); + return OffsetVector; +} + +void mitk::LogoOverlay::SetCornerPosition(const int &corner, mitk::BaseRenderer *renderer) +{ + SetIntProperty("Overlay.CornerPosition", corner, renderer); + Modified(); +} + +int mitk::LogoOverlay::GetCornerPosition(mitk::BaseRenderer *renderer) const +{ + int corner = 0; + GetIntProperty("Overlay.CornerPosition",corner,renderer); + return corner; +} + +void mitk::LogoOverlay::SetRelativeSize(const float &size, mitk::BaseRenderer *renderer) +{ + SetFloatProperty("Overlay.RelativeSize", size, renderer); + Modified(); +} + +float mitk::LogoOverlay::GetRelativeSize(mitk::BaseRenderer *renderer) const +{ + float size = 0; + GetFloatProperty("Overlay.RelativeSize",size,renderer); + return size; +} + +vtkProp* mitk::LogoOverlay::GetVtkProp(BaseRenderer *renderer) const +{ + LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); + return ls->m_LogoRep; +} diff --git a/Modules/Overlays/mitkLogoOverlay.h b/Modules/Overlays/mitkLogoOverlay.h new file mode 100644 index 0000000000..02f833cdd0 --- /dev/null +++ b/Modules/Overlays/mitkLogoOverlay.h @@ -0,0 +1,103 @@ +/*=================================================================== + + 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 LOGOOVERLAY_H +#define LOGOOVERLAY_H + +#include +#include +#include +#include "MitkCoreExports.h" + +class mitkVtkLogoRepresentation; +class vtkLogoWidget; +class vtkImageData; +class vtkImageReader2Factory; + +namespace mitk { + +/** \brief Displays a logo on the renderwindow */ +class MITK_CORE_EXPORT LogoOverlay : public mitk::VtkOverlay { +public: + + class LocalStorage : public mitk::Overlay::BaseLocalStorage + { + public: + /** \brief Actor of a 2D render window. */ + vtkSmartPointer m_LogoImage; + vtkSmartPointer m_LogoRep; + vtkSmartPointer m_LogoWidget; + + /** \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(LogoOverlay, mitk::VtkOverlay); + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + vtkSmartPointer m_readerFactory; + + void SetLogoImagePath(std::string text); + std::string GetLogoImagePath() const; + + /** \brief The relative offset to the corner position */ + void SetOffsetVector(const Point2D& OffsetVector, BaseRenderer* renderer = NULL); + Point2D GetOffsetVector(mitk::BaseRenderer* renderer = NULL) const; + + /** \brief The corner where the logo is displayed. + 0 = Bottom left + 1 = Bottom right + 2 = Top right + 3 = Top left*/ + void SetCornerPosition(const int& corner, BaseRenderer* renderer = NULL); + int GetCornerPosition(mitk::BaseRenderer* renderer = NULL) const; + + void SetRelativeSize(const float &size, BaseRenderer* renderer = NULL); + float GetRelativeSize(mitk::BaseRenderer* renderer = NULL) const; + +protected: + + /** \brief The LocalStorageHandler holds all LocalStorages for the render windows. */ + mutable mitk::LocalStorageHandler m_LSH; + + virtual vtkProp *GetVtkProp(BaseRenderer *renderer) const; + void UpdateVtkOverlay(mitk::BaseRenderer *renderer); + + /** \brief explicit constructor which disallows implicit conversions */ + explicit LogoOverlay(); + + /** \brief virtual destructor in order to derive from this class */ + virtual ~LogoOverlay(); + +private: + + /** \brief copy constructor */ + LogoOverlay( const LogoOverlay &); + + /** \brief assignment operator */ + LogoOverlay &operator=(const LogoOverlay &); + +}; + +} // namespace mitk +#endif // LOGOOVERLAY_H + diff --git a/Modules/Overlays/mitkVtkLogoRepresentation.cxx b/Modules/Overlays/mitkVtkLogoRepresentation.cxx new file mode 100644 index 0000000000..64676280c6 --- /dev/null +++ b/Modules/Overlays/mitkVtkLogoRepresentation.cxx @@ -0,0 +1,185 @@ +/*=================================================================== + + 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 "mitkVtkLogoRepresentation.h" +#include "vtkCallbackCommand.h" +#include "vtkObjectFactory.h" +#include "vtkPoints.h" +#include "vtkCellArray.h" +#include "vtkPolyData.h" +#include "vtkPolyDataMapper2D.h" +#include "vtkProperty2D.h" +#include "vtkActor2D.h" +#include "vtkPolyData.h" +#include "vtkTexture.h" +#include "vtkPolyDataMapper2D.h" +#include "vtkFloatArray.h" +#include "vtkPointData.h" +#include "vtkImageData.h" +#include "vtkPropCollection.h" +#include "vtkRenderer.h" +#include "vtkWindow.h" + + +vtkStandardNewMacro(mitkVtkLogoRepresentation); + +//---------------------------------------------------------------------- +inline void mitkVtkLogoRepresentation::AdjustImageSize(double o[2], + double borderSize[2], + double imageSize[2]) +{ + // Scale the image to fit with in the border. + // Also update the origin so the image is centered. + double r0 = borderSize[0]/imageSize[0]; + double r1 = borderSize[1]/imageSize[1]; + if ( r0 > r1 ) + { + imageSize[0] *= r1; + imageSize[1] *= r1; + } + else + { + imageSize[0] *= r0; + imageSize[1] *= r0; + } +} + +//------------------------------------------------------------------------- +void mitkVtkLogoRepresentation::BuildRepresentation() +{ + if ( this->GetMTime() > this->BuildTime || + (this->Renderer && this->Renderer->GetVTKWindow() && + this->Renderer->GetVTKWindow()->GetMTime() > this->BuildTime) ) + { + + // Determine and adjust the size of the image + if ( this->Image ) + { + double imageSize[2], borderSize[2], o[2]; + imageSize[0] = 0.0; + imageSize[1] = 0.0; + //this->Image->Update(); + if ( this->Image->GetDataDimension() == 2 ) + { + int dims[3]; + this->Image->GetDimensions(dims); + imageSize[0] = static_cast(dims[0]); + imageSize[1] = static_cast(dims[1]); + } + int *p1 = this->PositionCoordinate-> + GetComputedDisplayValue(this->Renderer); + int *p2 = this->Position2Coordinate-> + GetComputedDisplayValue(this->Renderer); + borderSize[0] = p2[0]; + borderSize[1] = p2[1]; + o[0] = static_cast(p1[0]); + o[1] = static_cast(p1[1]); + + // this preserves the image aspect ratio. The image is + // centered around the center of the bordered ragion. + this->AdjustImageSize(o,borderSize,imageSize); + + // Update the points + this->Texture->SetInputData(this->Image); + int* size = this->Renderer->GetSize(); + + switch(this->cornerPosition) + { + case 0: + { + this->TexturePoints->SetPoint(0, o[0],o[1],0.0); + this->TexturePoints->SetPoint(1, o[0]+imageSize[0],o[1],0.0); + this->TexturePoints->SetPoint(2, o[0]+imageSize[0],o[1]+imageSize[1],0.0); + this->TexturePoints->SetPoint(3, o[0],o[1]+imageSize[1],0.0); + break; + } + case 1: + { + o[0] = size[0]-o[0]; + this->TexturePoints->SetPoint(0, o[0]-imageSize[0],o[1],0.0); + this->TexturePoints->SetPoint(1, o[0],o[1],0.0); + this->TexturePoints->SetPoint(2, o[0],o[1]+imageSize[1],0.0); + this->TexturePoints->SetPoint(3, o[0]-imageSize[0],o[1]+imageSize[1],0.0); + break; + } + case 2: + { + o[0] = size[0]-o[0]; + o[1] = size[1]-o[1]; + this->TexturePoints->SetPoint(0, o[0]-imageSize[0],o[1]-imageSize[1],0.0); + this->TexturePoints->SetPoint(1, o[0],o[1]-imageSize[1],0.0); + this->TexturePoints->SetPoint(2, o[0],o[1],0.0); + this->TexturePoints->SetPoint(3, o[0]-imageSize[0],o[1],0.0); + break; + } + case 3: + { + o[1] = size[1]-o[1]; + this->TexturePoints->SetPoint(0, o[0],o[1]-imageSize[1],0.0); + this->TexturePoints->SetPoint(1, o[0]+imageSize[0],o[1]-imageSize[1],0.0); + this->TexturePoints->SetPoint(2, o[0]+imageSize[0],o[1],0.0); + this->TexturePoints->SetPoint(3, o[0],o[1],0.0); + break; + } + default: + { + this->TexturePoints->SetPoint(0, o[0],o[1],0.0); + this->TexturePoints->SetPoint(1, o[0]+imageSize[0],o[1],0.0); + this->TexturePoints->SetPoint(2, o[0]+imageSize[0],o[1]+imageSize[1],0.0); + this->TexturePoints->SetPoint(3, o[0],o[1]+imageSize[1],0.0); + } + } + + + } + } +} + +mitkVtkLogoRepresentation::mitkVtkLogoRepresentation() : cornerPosition(0) +{ + +} + +mitkVtkLogoRepresentation::~mitkVtkLogoRepresentation() +{ + +} + +//------------------------------------------------------------------------- +void mitkVtkLogoRepresentation::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); + + if ( this->Image ) + { + os << indent << "Image:\n"; + this->Image->PrintSelf(os,indent.GetNextIndent()); + } + else + { + os << indent << "Image: (none)\n"; + } + + if ( this->ImageProperty ) + { + os << indent << "Image Property:\n"; + this->ImageProperty->PrintSelf(os,indent.GetNextIndent()); + } + else + { + os << indent << "Image Property: (none)\n"; + } +} diff --git a/Modules/Overlays/mitkVtkLogoRepresentation.h b/Modules/Overlays/mitkVtkLogoRepresentation.h new file mode 100644 index 0000000000..021be6c943 --- /dev/null +++ b/Modules/Overlays/mitkVtkLogoRepresentation.h @@ -0,0 +1,56 @@ +/*=================================================================== + + The Medical Imaging Interaction Toolkit (MITK) + + Copyright (c) German Cancer Research Center, + Division of Medical and Biological Informatics. + All rights reserved. + + This software is distributed WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. + + See LICENSE.txt or http://www.mitk.org for details. + + ===================================================================*/ + + +#ifndef __mitkVtkLogoRepresentation_h +#define __mitkVtkLogoRepresentation_h + +#include "vtkLogoRepresentation.h" + +class mitkVtkLogoRepresentation : public vtkLogoRepresentation +{ +public: + + // Description: + // Instantiate this class. + static mitkVtkLogoRepresentation *New(); + + // Description: + // Standard VTK class methods. + vtkTypeMacro(mitkVtkLogoRepresentation,vtkLogoRepresentation); + void PrintSelf(ostream& os, vtkIndent indent); + + // Description: + // Satisfy the superclasses' API. + virtual void BuildRepresentation(); + + void SetCornerPosition(int corner){cornerPosition = corner;} + +protected: + mitkVtkLogoRepresentation(); + ~mitkVtkLogoRepresentation(); + + // Helper methods + void AdjustImageSize(double o[2], double borderSize[2], double imageSize[2]); + + int cornerPosition; + +private: + mitkVtkLogoRepresentation(const mitkVtkLogoRepresentation&); //Not implemented + void operator=(const mitkVtkLogoRepresentation&); //Not implemented +}; + +#endif