diff --git a/Modules/LegacyGL/files.cmake b/Modules/LegacyGL/files.cmake index 4fc7478a99..40b8041b83 100644 --- a/Modules/LegacyGL/files.cmake +++ b/Modules/LegacyGL/files.cmake @@ -1,13 +1,15 @@ #We are deprecated. Please don't use us. set(H_FILES mitkGLMapper2D.h mitkGL.h ) set(CPP_FILES mitkPlaneGeometryDataGLMapper2D.cpp mitkGLMapper.cpp mitkPointSetGLMapper2D.cpp mitkSurfaceGLMapper2D.cpp + mitkVtkGLMapperWrapper.cpp + vtkGLMapperProp.cpp ) diff --git a/Modules/LegacyGL/mitkGLMapper.h b/Modules/LegacyGL/mitkGLMapper.h index 649df851b9..56a32540d0 100644 --- a/Modules/LegacyGL/mitkGLMapper.h +++ b/Modules/LegacyGL/mitkGLMapper.h @@ -1,105 +1,108 @@ /*=================================================================== 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 MITKGLMAPPER_H_HEADER_INCLUDED_C197C872 #define MITKGLMAPPER_H_HEADER_INCLUDED_C197C872 #include #include "mitkMapper.h" #include "mitkBaseRenderer.h" #include "mitkVtkPropRenderer.h" namespace mitk { /** \brief Base class of all OpenGL-based mappers. * * Those must implement the abstract method Paint(BaseRenderer), which is called by * method MitkRender(). * The Paint() method should be used to paint into a renderer via OpenGL-drawing commands. * The OpenGL context matrices (GL_MODELVIEWMATRIX/GL_PROJECTIONMATRIX) are preinitialized by * the mitkVtkPropRenderer so that the origin of the 2D-coordinate system of the 2D render * window is located in the lower left corner and has the width and height in display pixels * of the respective renderwindow. The x-axis is horizontally oriented, while the y-axis is * vertically oriented. The drawing commands are directly interpreted as display coordinates. * ApplyColorAndOpacity() can be used in the subclasses to apply color and opacity properties * read from the PropertyList. * * @deprecatedSince{2015_03} GLMappers are no longer supported in the rendering pipeline. * Please use mitkVtkMapper instead or consider writing your own vtk classes, such as vtkActor * or vtkMapper * \ingroup Mapper */ class MitkLegacyGL_EXPORT GLMapper : public Mapper { public: + + mitkClassMacro(GLMapper, Mapper); + /** \brief Do the painting into the \a renderer */ virtual void Paint(mitk::BaseRenderer *renderer) = 0; /** \brief Apply color and opacity properties read from the PropertyList * \deprecatedSince{2013_03} Use ApplyColorAndOpacityProperties(...) instead */ DEPRECATED(inline virtual void ApplyProperties(mitk::BaseRenderer* renderer)) { ApplyColorAndOpacityProperties(renderer); } /** \brief Apply color and opacity properties read from the PropertyList. * The actor is not used in the GLMappers. Called by mapper subclasses. */ virtual void ApplyColorAndOpacityProperties(mitk::BaseRenderer* renderer, vtkActor* actor = NULL); /** \brief Checks visibility and calls the paint method * * Note: The enumeration is disregarded, since OpenGL rendering only needs a * single render pass. */ void MitkRender(mitk::BaseRenderer* renderer, mitk::VtkPropRenderer::RenderType type); /** \brief Returns whether this is a vtk-based mapper * \return false, since all mappers deriving from this class are OpenGL mappers * \deprecatedSince{2013_03} All mappers of superclass VTKMapper are vtk based, use a dynamic_cast instead */ DEPRECATED( virtual bool IsVtkBased() const ); /** \brief Returns whether this mapper allows picking in the renderwindow virtual bool IsPickable() const { return false; }*/ protected: /** constructor */ GLMapper(); /** virtual destructor in order to derive from this class */ virtual ~GLMapper(); private: /** copy constructor */ GLMapper( const GLMapper &); /** assignment operator */ GLMapper & operator=(const GLMapper &); }; } // namespace mitk #endif /* MITKGLMAPPER2D_H_HEADER_INCLUDED_C197C872 */ diff --git a/Modules/LegacyGL/mitkVtkGLMapperWrapper.cpp b/Modules/LegacyGL/mitkVtkGLMapperWrapper.cpp new file mode 100644 index 0000000000..b11aa4d571 --- /dev/null +++ b/Modules/LegacyGL/mitkVtkGLMapperWrapper.cpp @@ -0,0 +1,160 @@ +/*=================================================================== + +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 "mitkVtkGLMapperWrapper.h" + +//mitk includes +#include "mitkDataNode.h" +#include "vtkGLMapperProp.h" +#include "mitkGL.h" + +// constructor LocalStorage +mitk::VtkGLMapperWrapper::LocalStorage::LocalStorage() +{ + m_GLMapperProp = vtkSmartPointer::New(); +} +// destructor LocalStorage +mitk::VtkGLMapperWrapper::LocalStorage::~LocalStorage() +{ +} + +// constructor VtkGLMapperWrapper +mitk::VtkGLMapperWrapper::VtkGLMapperWrapper(GLMapper::Pointer mitkGLMapper) +{ + m_MitkGLMapper = mitkGLMapper; +} + +// destructor +mitk::VtkGLMapperWrapper::~VtkGLMapperWrapper() +{ +} + +// returns propassembly +vtkProp* mitk::VtkGLMapperWrapper::GetVtkProp(mitk::BaseRenderer * renderer) +{ + LocalStorage *ls = m_LSH.GetLocalStorage(renderer); + return ls->m_GLMapperProp; +} + +void mitk::VtkGLMapperWrapper::GenerateDataForRenderer(mitk::BaseRenderer *renderer) +{ + m_MitkGLMapper->SetDataNode(GetDataNode()); + LocalStorage *ls = m_LSH.GetLocalStorage(renderer); + ls->m_GLMapperProp->SetBaseRenderer(renderer); + ls->m_GLMapperProp->SetWrappedGLMapper(m_MitkGLMapper); +} + +void mitk::VtkGLMapperWrapper::ApplyColorAndOpacityProperties(mitk::BaseRenderer *renderer, vtkActor *actor) +{ + m_MitkGLMapper->ApplyColorAndOpacityProperties(renderer,actor); +} + +void mitk::VtkGLMapperWrapper::MitkRender(mitk::BaseRenderer *renderer, mitk::VtkPropRenderer::RenderType type) +{ + if(type != mitk::VtkPropRenderer::Opaque) + return; + Enable2DOpenGL(renderer); + Superclass::MitkRender(renderer,type); + Disable2DOpenGL(); +} + +/*! +\brief +Enable2DOpenGL() and Disable2DOpenGL() are used to switch between 2D rendering (orthographic projection) and 3D rendering (perspective projection) +*/ +void mitk::VtkGLMapperWrapper::Enable2DOpenGL(mitk::BaseRenderer *renderer) +{ + GLint iViewport[4]; + + // Get a copy of the viewport + glGetIntegerv( GL_VIEWPORT, iViewport ); + + // Save a copy of the projection matrix so that we can restore it + // when it's time to do 3D rendering again. + glMatrixMode( GL_PROJECTION ); + glPushMatrix(); + glLoadIdentity(); + + // Set up the orthographic projection + const mitk::DisplayGeometry* displayGeometry = renderer->GetDisplayGeometry(); + + float displayGeometryWidth = displayGeometry->GetSizeInDisplayUnits()[0]; + float displayGeometryHeight = displayGeometry->GetSizeInDisplayUnits()[1]; + float viewportWidth = iViewport[2]; + float viewportHeight = iViewport[3]; + + /* + The following makes OpenGL mappers draw into the same viewport + that is used by VTK when someone calls vtkRenderer::SetViewport(). + + The parameters of glOrtho describe what "input" coordinates + (display coordinates generated by the OpenGL mappers) are transformed + into the region defined by the viewport. The call has to consider + that the scene is fit vertically and centered horizontally. + + Problem: this is a crude first step towards rendering into viewports. + - mitkViewportRenderingTest demonstrates the non-interactive rendering + that is now possible + - interactors that measure mouse movement in pixels will + probably run into problems with display-to-world transformation + + A proper solution should probably modify the DisplayGeometry to + correctly describe the viewport. + */ + // iViewport is (x,y,width,height) + // glOrtho expects (left,right,bottom,top,znear,zfar) + glOrtho( 0 + - 0.5 * (viewportWidth/viewportHeight-1.0)*displayGeometryHeight + + 0.5 * (displayGeometryWidth - displayGeometryHeight) + , + displayGeometryWidth + + 0.5 * (viewportWidth/viewportHeight-1.0)*displayGeometryHeight + - 0.5 * (displayGeometryWidth - displayGeometryHeight) + , + 0, displayGeometryHeight, + -1.0, 1.0 + ); + + glMatrixMode( GL_MODELVIEW ); + glPushMatrix(); + glLoadIdentity(); + + // Make sure depth testing and lighting are disabled for 2D rendering until + // we are finished rendering in 2D + glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT ); + glDisable( GL_DEPTH_TEST ); + glDisable( GL_LIGHTING ); + // disable the texturing here so crosshair is painted in the correct colors + // vtk will reenable texturing every time it is needed + glDisable( GL_TEXTURE_1D ); + glDisable( GL_TEXTURE_2D ); + glLineWidth(1.0); +} + +/*! +\brief Initialize the VtkPropRenderer + +Enable2DOpenGL() and Disable2DOpenGL() are used to switch between 2D rendering (orthographic projection) and 3D rendering (perspective projection) +*/ +void mitk::VtkGLMapperWrapper::Disable2DOpenGL() +{ + glPopAttrib(); + glMatrixMode( GL_PROJECTION ); + glPopMatrix(); + glMatrixMode( GL_MODELVIEW ); + glPopMatrix(); +} + diff --git a/Modules/LegacyGL/mitkVtkGLMapperWrapper.h b/Modules/LegacyGL/mitkVtkGLMapperWrapper.h new file mode 100644 index 0000000000..bd93b58187 --- /dev/null +++ b/Modules/LegacyGL/mitkVtkGLMapperWrapper.h @@ -0,0 +1,84 @@ +/*=================================================================== + +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 MITKVtkGLMapperWrapper_H_HEADER +#define MITKVtkGLMapperWrapper_H_HEADER + + +#include +#include "mitkVtkMapper.h" +#include "mitkBaseRenderer.h" +#include "mitkLocalStorageHandler.h" +#include +#include "mitkGLMapper.h" + +class vtkGLMapperProp; + +namespace mitk { + + /** + * @brief Vtk-based 2D mapper for PointSet + */ + class MitkLegacyGL_EXPORT VtkGLMapperWrapper : public VtkMapper + { + public: + mitkClassMacro(VtkGLMapperWrapper, VtkMapper); + + mitkNewMacro1Param(Self,GLMapper::Pointer) + + itkCloneMacro(Self) + + /** \brief returns the a prop assembly */ + virtual vtkProp* GetVtkProp(mitk::BaseRenderer* renderer); + + virtual void GenerateDataForRenderer(mitk::BaseRenderer* renderer); + + /** \brief Internal class holding the mapper, actor, etc. for each of the 3 2D render windows */ + class LocalStorage : public mitk::Mapper::BaseLocalStorage + { + public: + /* constructor */ + LocalStorage(); + + /* destructor */ + ~LocalStorage(); + vtkSmartPointer m_GLMapperProp; + }; + + virtual void ApplyColorAndOpacityProperties(mitk::BaseRenderer* renderer, vtkActor * actor); + + void MitkRender(mitk::BaseRenderer* renderer, mitk::VtkPropRenderer::RenderType type); + + /** \brief The LocalStorageHandler holds all (three) LocalStorages for the three 2D render windows. */ + mitk::LocalStorageHandler m_LSH; + + protected: + + + GLMapper::Pointer m_MitkGLMapper; + /* constructor */ + VtkGLMapperWrapper(GLMapper::Pointer mitkGLMapper); + + /* destructor */ + virtual ~VtkGLMapperWrapper(); + void Enable2DOpenGL(mitk::BaseRenderer *renderer); + void Disable2DOpenGL(); + }; + +} // namespace mitk + +#endif /* MITKVtkGLMapperWrapper_H_HEADER_INCLUDED_C1902626 */ diff --git a/Modules/LegacyGL/vtkGLMapperProp.cpp b/Modules/LegacyGL/vtkGLMapperProp.cpp new file mode 100644 index 0000000000..44d9bcf12b --- /dev/null +++ b/Modules/LegacyGL/vtkGLMapperProp.cpp @@ -0,0 +1,68 @@ +/*=================================================================== + +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 "vtkGLMapperProp.h" + +#include + + +vtkStandardNewMacro(vtkGLMapperProp); + +vtkGLMapperProp::vtkGLMapperProp() +{ +} + +vtkGLMapperProp::~vtkGLMapperProp() +{ +} + +int vtkGLMapperProp::RenderOpaqueGeometry(vtkViewport *) +{ + if(!m_WrappedGLMapper || !m_BaseRenderer) + return 0; + + this->m_WrappedGLMapper->MitkRender(m_BaseRenderer, mitk::VtkPropRenderer::Opaque); +} + +int vtkGLMapperProp::RenderTranslucentPolygonalGeometry(vtkViewport *) +{ + return 0; +} + +int vtkGLMapperProp::RenderVolumetricGeometry(vtkViewport *) +{ + return 0; +} + +int vtkGLMapperProp::RenderOverlay(vtkViewport *) +{ + return 0; +} + +const mitk::GLMapper *vtkGLMapperProp::GetWrappedGLMapper() const +{ + return m_WrappedGLMapper; +} + +void vtkGLMapperProp::SetWrappedGLMapper(mitk::GLMapper* glMapper) +{ + this->m_WrappedGLMapper = glMapper; +} + +void vtkGLMapperProp::SetBaseRenderer(mitk::BaseRenderer *baseRenderer) +{ + this->m_BaseRenderer = baseRenderer; +} diff --git a/Modules/LegacyGL/vtkGLMapperProp.h b/Modules/LegacyGL/vtkGLMapperProp.h new file mode 100644 index 0000000000..fea9354ca7 --- /dev/null +++ b/Modules/LegacyGL/vtkGLMapperProp.h @@ -0,0 +1,58 @@ +/*=================================================================== + +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 vtkGLMapperProp_h +#define vtkGLMapperProp_h + +#include "MitkLegacyGLExports.h" + +#include +#include +#include "mitkGLMapper.h" + +/** + * @brief The vtkGLMapperProp class is a VtkProp, wrapping a GLMapper + */ +class MitkLegacyGL_EXPORT vtkGLMapperProp : public vtkProp +{ + public: + static vtkGLMapperProp* New(); + vtkTypeMacro(vtkGLMapperProp,vtkProp); + + /** + * @brief RenderOverlay Calls the render method of the actor and renders it. + * @param viewport viewport of the renderwindow. + * @return + */ + int RenderOverlay(vtkViewport* viewport); + int RenderVolumetricGeometry(vtkViewport *); + int RenderTranslucentPolygonalGeometry(vtkViewport *); + int RenderOpaqueGeometry(vtkViewport *); + + const mitk::GLMapper *GetWrappedGLMapper() const; + void SetWrappedGLMapper(mitk::GLMapper *glMapper); + + void SetBaseRenderer(mitk::BaseRenderer* baseRenderer); +protected: + + vtkGLMapperProp(); + virtual ~vtkGLMapperProp(); + + mitk::GLMapper* m_WrappedGLMapper; + mitk::BaseRenderer* m_BaseRenderer; + +}; +#endif /* vtkGLMapperProp2_h */ diff --git a/Modules/PlanarFigure/Algorithms/mitkPlanarFigureObjectFactory.cpp b/Modules/PlanarFigure/Algorithms/mitkPlanarFigureObjectFactory.cpp index 1b92af848d..d6c7d9794e 100644 --- a/Modules/PlanarFigure/Algorithms/mitkPlanarFigureObjectFactory.cpp +++ b/Modules/PlanarFigure/Algorithms/mitkPlanarFigureObjectFactory.cpp @@ -1,146 +1,147 @@ /*=================================================================== 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 "mitkPlanarFigureObjectFactory.h" #include "mitkPlanarFigureWriter.h" #include "mitkCoreObjectFactory.h" #include "mitkPlanarFigureIOFactory.h" #include "mitkPlanarFigureWriterFactory.h" #include "mitkPlanarFigure.h" #include "mitkPlanarFigureMapper2D.h" #include "mitkPlanarFigureVtkMapper3D.h" +#include "mitkVtkGLMapperWrapper.h" typedef std::multimap MultimapType; mitk::PlanarFigureObjectFactory::PlanarFigureObjectFactory() : m_PlanarFigureIOFactory(PlanarFigureIOFactory::New().GetPointer()) , m_PlanarFigureWriterFactory(PlanarFigureWriterFactory::New().GetPointer()) { static bool alreadyDone = false; if ( !alreadyDone ) { itk::ObjectFactoryBase::RegisterFactory( m_PlanarFigureIOFactory ); itk::ObjectFactoryBase::RegisterFactory( m_PlanarFigureWriterFactory ); m_FileWriters.push_back( PlanarFigureWriter::New().GetPointer() ); CreateFileExtensionsMap(); alreadyDone = true; } } mitk::PlanarFigureObjectFactory::~PlanarFigureObjectFactory() { itk::ObjectFactoryBase::UnRegisterFactory(m_PlanarFigureWriterFactory); itk::ObjectFactoryBase::UnRegisterFactory(m_PlanarFigureIOFactory); } mitk::Mapper::Pointer mitk::PlanarFigureObjectFactory::CreateMapper(mitk::DataNode* node, MapperSlotId id) { mitk::Mapper::Pointer newMapper=NULL; mitk::BaseData *data = node->GetData(); if ( dynamic_cast(data) != NULL ) { if ( id == mitk::BaseRenderer::Standard2D ) { - newMapper = mitk::PlanarFigureMapper2D::New(); + newMapper = mitk::VtkGLMapperWrapper::New(mitk::PlanarFigureMapper2D::New().GetPointer()); newMapper->SetDataNode(node); } else if ( id == mitk::BaseRenderer::Standard3D ) { newMapper = mitk::PlanarFigureVtkMapper3D::New(); newMapper->SetDataNode(node); } } return newMapper; } void mitk::PlanarFigureObjectFactory::SetDefaultProperties(mitk::DataNode* node) { if ( node == NULL ) { return; } mitk::DataNode::Pointer nodePointer = node; mitk::PlanarFigure::Pointer pf = dynamic_cast( node->GetData() ); if ( pf.IsNotNull() ) { mitk::PlanarFigureMapper2D::SetDefaultProperties(node); node->AddProperty( "color", mitk::ColorProperty::New(1.0,1.0,1.0), NULL, true ); node->AddProperty( "opacity", mitk::FloatProperty::New(0.8), NULL, true ); node->AddProperty( "planarfigure.3drendering", mitk::BoolProperty::New(false), NULL, true ); } } const char* mitk::PlanarFigureObjectFactory::GetFileExtensions() { return ""; } mitk::CoreObjectFactoryBase::MultimapType mitk::PlanarFigureObjectFactory::GetFileExtensionsMap() { return m_FileExtensionsMap; } const char* mitk::PlanarFigureObjectFactory::GetSaveFileExtensions() { //return ";;Planar Figures (*.pf)"; // for mitk::PlanarFigure and derived classes std::string fileExtension; this->CreateFileExtensions(m_SaveFileExtensionsMap, fileExtension); return fileExtension.c_str(); }; mitk::CoreObjectFactoryBase::MultimapType mitk::PlanarFigureObjectFactory::GetSaveFileExtensionsMap() { return m_SaveFileExtensionsMap; } void mitk::PlanarFigureObjectFactory::CreateFileExtensionsMap() { m_FileExtensionsMap.insert(std::pair("*.pf", "Planar Figure Files")); m_SaveFileExtensionsMap.insert(std::pair("*.pf", "Planar Figure Files")); } void mitk::PlanarFigureObjectFactory::RegisterIOFactories() { } struct RegisterPlanarFigureObjectFactory{ RegisterPlanarFigureObjectFactory() : m_Factory( mitk::PlanarFigureObjectFactory::New() ) { mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory( m_Factory ); } ~RegisterPlanarFigureObjectFactory() { mitk::CoreObjectFactory::GetInstance()->UnRegisterExtraFactory( m_Factory ); } mitk::PlanarFigureObjectFactory::Pointer m_Factory; }; static RegisterPlanarFigureObjectFactory registerPlanarFigureObjectFactory;