diff --git a/Core/Code/Rendering/mitkGradientBackground.cpp b/Core/Code/Rendering/mitkGradientBackground.cpp index 1cfaf63290..4da1fcb557 100644 --- a/Core/Code/Rendering/mitkGradientBackground.cpp +++ b/Core/Code/Rendering/mitkGradientBackground.cpp @@ -1,239 +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 "mitkGradientBackground.h" - #include "mitkVtkLayerController.h" - #include #include #include #include #include #include #include #include #include #include #include #include #include #include - mitk::GradientBackground::GradientBackground() { m_RenderWindow = NULL; - m_Renderer = vtkRenderer::New(); - m_Actor = vtkActor::New(); - m_Mapper = vtkPolyDataMapper::New(); - m_Lut = vtkLookupTable::New(); - m_Plane = vtkPolyData::New(); + m_Renderer = vtkSmartPointer::New(); + m_Actor = vtkSmartPointer::New(); + m_Mapper = vtkSmartPointer::New(); + m_Lut = vtkSmartPointer::New(); + m_Plane = vtkSmartPointer::New(); - vtkPoints* points = vtkPoints::New( ); + vtkSmartPointer points = vtkSmartPointer::New(); points->InsertPoint(0,-10,0,0); points->InsertPoint(1,-10,1,0); points->InsertPoint(2,10,1,0); points->InsertPoint(3,10,0,0); - vtkCellArray* cellArray = vtkCellArray::New(); + vtkSmartPointer cellArray = vtkSmartPointer::New(); cellArray->InsertNextCell(4); cellArray->InsertCellPoint(0); cellArray->InsertCellPoint(1); cellArray->InsertCellPoint(2); cellArray->InsertCellPoint(3); - vtkUnsignedIntArray* data = vtkUnsignedIntArray::New(); + vtkSmartPointer data = vtkSmartPointer::New(); data->InsertTuple1(0,1); data->InsertTuple1(1,0); data->InsertTuple1(2,0); data->InsertTuple1(3,1); m_Plane->SetPoints( points ); m_Plane->SetPolys( cellArray ); m_Plane->GetPointData()->SetScalars( data ); - points->Delete(); - cellArray->Delete(); - data->Delete(); - m_Lut->SetNumberOfColors( 2 ); m_Lut->Build(); m_Lut->SetTableValue( m_Lut->GetIndex(0), 1, 1, 1 ); m_Lut->SetTableValue( m_Lut->GetIndex(1), 0, 0, 0 ); m_Mapper->SetInputData( m_Plane ); m_Mapper->SetLookupTable( m_Lut ); - //m_Mapper->ImmediateModeRenderingOn(); - m_Actor->SetMapper( m_Mapper ); m_Renderer->AddActor( m_Actor ); m_Renderer->InteractiveOff(); - m_Renderer->GetActiveCamera()->ParallelProjectionOn(); - m_Renderer->ResetCamera(); - m_Renderer->GetActiveCamera()->SetParallelScale(0.5); } mitk::GradientBackground::~GradientBackground() { if ( m_RenderWindow != NULL ) if ( this->IsEnabled() ) this->Disable(); - - if ( m_Plane != NULL ) - m_Plane->Delete(); - - if( m_Lut != NULL ) - m_Lut->Delete(); - - if ( m_Mapper != NULL ) - m_Mapper->Delete(); - - if ( m_Actor!=NULL ) - m_Actor->Delete(); - - if ( m_Renderer != NULL ) - m_Renderer->Delete(); } /** * Sets the renderwindow, in which the gradient background * will be shown. Make sure, you have called this function * before calling Enable() */ -void mitk::GradientBackground::SetRenderWindow( vtkRenderWindow * renderWindow ) +void mitk::GradientBackground::SetRenderWindow(vtkSmartPointer renderWindow ) { m_RenderWindow = renderWindow; } /** * Returns the vtkRenderWindow, which is used * for displaying the gradient background */ -vtkRenderWindow* mitk::GradientBackground::GetRenderWindow() +vtkSmartPointer mitk::GradientBackground::GetRenderWindow() { return m_RenderWindow; } /** * Returns the renderer responsible for * rendering the color gradient into the * vtkRenderWindow */ -vtkRenderer* mitk::GradientBackground::GetVtkRenderer() +vtkSmartPointer mitk::GradientBackground::GetVtkRenderer() { return m_Renderer; } /** * Returns the actor associated with the color gradient */ -vtkActor* mitk::GradientBackground::GetActor() +vtkSmartPointer mitk::GradientBackground::GetActor() { return m_Actor; } /** * Returns the mapper associated with the color * gradient. */ -vtkPolyDataMapper* mitk::GradientBackground::GetMapper() +vtkSmartPointer mitk::GradientBackground::GetMapper() { return m_Mapper; } - /** * Sets the gradient colors. The gradient * will smoothly fade from color1 to color2 */ void mitk::GradientBackground::SetGradientColors( double r1, double g1, double b1, double r2, double g2, double b2 ) { m_Lut->SetTableValue( m_Lut->GetIndex(0), r1, g1, b1 ); m_Lut->SetTableValue( m_Lut->GetIndex(1), r2, g2, b2 ); } - void mitk::GradientBackground::SetUpperColor(double r, double g, double b ) { m_Lut->SetTableValue( m_Lut->GetIndex(0), r, g, b ); } - void mitk::GradientBackground::SetLowerColor(double r, double g, double b ) { m_Lut->SetTableValue( m_Lut->GetIndex(1), r, g, b ); } - /** * Enables drawing of the color gradient background. * If you want to disable it, call the Disable() function. */ void mitk::GradientBackground::Enable() { mitk::VtkLayerController::GetInstance(m_RenderWindow)->InsertBackgroundRenderer(m_Renderer,true); } /** * Disables drawing of the color gradient background. * If you want to enable it, call the Enable() function. */ void mitk::GradientBackground::Disable() { if ( this->IsEnabled() ) { mitk::VtkLayerController::GetInstance(m_RenderWindow)->RemoveRenderer(m_Renderer); } } - - /** * Checks, if the gradient background is currently * enabled (visible) */ bool mitk::GradientBackground::IsEnabled() { if ( m_RenderWindow == NULL ) return false; else return ( mitk::VtkLayerController::GetInstance(m_RenderWindow)->IsRendererInserted(m_Renderer)); } - -void mitk::GradientBackground::SetRequestedRegionToLargestPossibleRegion() -{ - //nothing to do -} - -bool mitk::GradientBackground::RequestedRegionIsOutsideOfTheBufferedRegion() -{ - return false; -} - -bool mitk::GradientBackground::VerifyRequestedRegion() -{ - return true; -} - -void mitk::GradientBackground::SetRequestedRegion( const itk::DataObject*) -{ - //nothing to do -} - diff --git a/Core/Code/Rendering/mitkGradientBackground.h b/Core/Code/Rendering/mitkGradientBackground.h index 1b56ef0ff8..470df63a21 100644 --- a/Core/Code/Rendering/mitkGradientBackground.h +++ b/Core/Code/Rendering/mitkGradientBackground.h @@ -1,160 +1,127 @@ /*=================================================================== 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 _vtk_Gradient_Background_h_ -#define _vtk_Gradient_Background_h_ +#ifndef mitkGradientBackground_h +#define mitkGradientBackground_h - -#include +#include +#include +#include class vtkRenderer; class vtkMapper; class vtkActor; class vtkPolyDataMapper; class vtkLookupTable; class vtkPolyData; class vtkRenderWindow; namespace mitk { class RenderWindow; /** * Displays a color gradient in the background * of a vtkRenderWindow. * The gradient ist faked by displaying a non-interactable * smoothly shaded plane in a separate layer behind the * scene. After setting the renderwindow, the gradient may be * activated by calling Enable() */ -class MITK_CORE_EXPORT GradientBackground : public BaseData +class MITK_CORE_EXPORT GradientBackground : public itk::Object { public: - mitkClassMacro( GradientBackground, BaseData ); + mitkClassMacro( GradientBackground, itk::Object ); itkFactorylessNewMacro(Self) itkCloneMacro(Self) /** * Sets the renderwindow, in which the gradient background * will be shown. Make sure, you have called this function * before calling Enable() */ - virtual void SetRenderWindow( vtkRenderWindow* renderWindow ); + virtual void SetRenderWindow( vtkSmartPointer renderWindow ); /** * Returns the vtkRenderWindow, which is used * for displaying the gradient background */ - virtual vtkRenderWindow* GetRenderWindow(); + virtual vtkSmartPointer GetRenderWindow(); /** * Returns the renderer responsible for * rendering the color gradient into the * vtkRenderWindow */ - virtual vtkRenderer* GetVtkRenderer(); + virtual vtkSmartPointer GetVtkRenderer(); /** * Returns the actor associated with the color gradient */ - virtual vtkActor* GetActor(); + virtual vtkSmartPointer GetActor(); /** * Returns the mapper associated with the color * gradient. */ - virtual vtkPolyDataMapper* GetMapper(); + virtual vtkSmartPointer GetMapper(); /** * Sets the gradient colors. The gradient * will smoothly fade from color1 to color2 */ virtual void SetGradientColors( double r1, double g1, double b1, double r2, double g2, double b2); virtual void SetUpperColor(double r, double g, double b ); virtual void SetLowerColor(double r, double g, double b ); /** * Enables drawing of the color gradient background. * If you want to disable it, call the Disable() function. */ virtual void Enable(); /** * Disables drawing of the color gradient background. * If you want to enable it, call the Enable() function. */ virtual void Disable(); /** * Checks, if the gradient background is currently * enabled (visible) */ virtual bool IsEnabled(); - /** - * Empty implementation, since the GradientBackground doesn't - * support the requested region concept - */ - virtual void SetRequestedRegionToLargestPossibleRegion(); - - /** - * Empty implementation, since the GradientBackground doesn't - * support the requested region concept - */ - virtual bool RequestedRegionIsOutsideOfTheBufferedRegion(); - - /** - * Empty implementation, since the GradientBackground doesn't - * support the requested region concept - */ - virtual bool VerifyRequestedRegion(); - - /** - * Empty implementation, since the GradientBackground doesn't - * support the requested region concept - */ - virtual void SetRequestedRegion( const itk::DataObject*); - protected: - /** - * Constructor - */ GradientBackground(); - - /** - * Destructor - */ ~GradientBackground(); - vtkRenderWindow* m_RenderWindow; + vtkSmartPointer m_RenderWindow; - vtkRenderer* m_Renderer; + vtkSmartPointer m_Renderer; - vtkActor* m_Actor; + vtkSmartPointer m_Actor; - vtkPolyDataMapper* m_Mapper; + vtkSmartPointer m_Mapper; - vtkLookupTable* m_Lut; + vtkSmartPointer m_Lut; - vtkPolyData* m_Plane; + vtkSmartPointer m_Plane; }; - } //end of namespace mitk -#endif - - +#endif //mitkGradientBackground_h