diff --git a/Core/Code/Controllers/mitkVtkLayerController.cpp b/Core/Code/Controllers/mitkVtkLayerController.cpp index 2213b78638..691a3f8bfc 100644 --- a/Core/Code/Controllers/mitkVtkLayerController.cpp +++ b/Core/Code/Controllers/mitkVtkLayerController.cpp @@ -1,342 +1,342 @@ /*=================================================================== 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 "mitkVtkLayerController.h" #include #include #include #include #include mitk::VtkLayerController::vtkLayerControllerMapType mitk::VtkLayerController::s_LayerControllerMap; -mitk::VtkLayerController * mitk::VtkLayerController::GetInstance(vtkRenderWindow* renWin) +mitk::VtkLayerController* mitk::VtkLayerController::GetInstance(vtkSmartPointer renWin) { for(vtkLayerControllerMapType::iterator mapit = s_LayerControllerMap.begin(); mapit != s_LayerControllerMap.end(); mapit++) { if( (*mapit).first == renWin) return (*mapit).second; } return NULL; } -void mitk::VtkLayerController::AddInstance(vtkRenderWindow* renWin, vtkRenderer * mitkSceneRenderer) +void mitk::VtkLayerController::AddInstance(vtkSmartPointer renWin, + vtkSmartPointer mitkSceneRenderer) { // ensure that no vtkRenderWindow is managed twice mitk::VtkLayerController::RemoveInstance(renWin); // instanciate controller, add it to the map mitk::VtkLayerController* ControllerInstance = new mitk::VtkLayerController(renWin); ControllerInstance->InsertSceneRenderer(mitkSceneRenderer); s_LayerControllerMap.insert(vtkLayerControllerMapType::value_type(renWin,ControllerInstance)); } -void mitk::VtkLayerController::RemoveInstance(vtkRenderWindow* renWin) +void mitk::VtkLayerController::RemoveInstance(vtkSmartPointer renWin) { vtkLayerControllerMapType::iterator mapit = s_LayerControllerMap.find(renWin); if(mapit != s_LayerControllerMap.end()) { delete mapit->second; s_LayerControllerMap.erase( mapit ); } } -mitk::VtkLayerController::VtkLayerController(vtkRenderWindow* renderWindow) +mitk::VtkLayerController::VtkLayerController(vtkSmartPointer renderWindow) { m_RenderWindow = renderWindow; m_RenderWindow->Register( NULL ); m_BackgroundRenderers.clear(); m_ForegroundRenderers.clear(); m_SceneRenderers.clear(); } mitk::VtkLayerController::~VtkLayerController() { if ( m_RenderWindow != NULL ) { m_RenderWindow->UnRegister( NULL ); } } /** * Connects a VTK renderer with a vtk renderwindow. The renderer will be rendered in the background. * With forceAbsoluteBackground set true a renderer can be placed at the absolute background of the scene. * Multiple calls with forceAbsoluteBackground set true will set the latest registered renderer as background. */ -void mitk::VtkLayerController::InsertBackgroundRenderer(vtkRenderer* renderer, bool forceAbsoluteBackground) +void mitk::VtkLayerController::InsertBackgroundRenderer(vtkSmartPointer + renderer, bool forceAbsoluteBackground) { if(renderer == NULL) return; // Remove renderer if it already exists RemoveRenderer(renderer); if(forceAbsoluteBackground) { RendererVectorType::iterator it = m_BackgroundRenderers.begin(); m_BackgroundRenderers.insert(it,renderer); } else m_BackgroundRenderers.push_back(renderer); UpdateLayers(); } /** * Connects a VTK renderer with a vtk renderwindow. The renderer will be rendered in the foreground. * With forceAbsoluteBackground set true a renderer can be placed at the absolute foreground of the scene. * Multiple calls with forceAbsoluteForeground set true will set the latest registered renderer as foreground. */ -void mitk::VtkLayerController::InsertForegroundRenderer(vtkRenderer* renderer, bool forceAbsoluteForeground) +void mitk::VtkLayerController::InsertForegroundRenderer(vtkSmartPointer renderer, + bool forceAbsoluteForeground) { if(renderer == NULL) return; // Remove renderer if it already exists RemoveRenderer(renderer); if(forceAbsoluteForeground) { RendererVectorType::iterator it = m_ForegroundRenderers.begin(); m_ForegroundRenderers.insert(it,renderer); } else m_ForegroundRenderers.push_back(renderer); UpdateLayers(); } /** * Returns the Scene Renderer */ -vtkRenderer* mitk::VtkLayerController::GetSceneRenderer() +vtkSmartPointer mitk::VtkLayerController::GetSceneRenderer() { if(m_SceneRenderers.size() > 0) { RendererVectorType::iterator it = m_SceneRenderers.begin(); return (*it); } else return NULL; } /** * Connects a VTK renderer with a vtk renderwindow. The renderer will be rendered between background renderers and * foreground renderers. */ -void mitk::VtkLayerController::InsertSceneRenderer(vtkRenderer* renderer) +void mitk::VtkLayerController::InsertSceneRenderer(vtkSmartPointer renderer) { if(renderer == NULL) return; // Remove renderer if it already exists RemoveRenderer(renderer); m_SceneRenderers.push_back(renderer); UpdateLayers(); } /** * A renderer which has been inserted via a insert... function can be removed from the vtkRenderWindow with * RemoveRenderer. */ -void mitk::VtkLayerController::RemoveRenderer(vtkRenderer* renderer) +void mitk::VtkLayerController::RemoveRenderer(vtkSmartPointer renderer) { RendererVectorType::iterator it; // background layers if(m_BackgroundRenderers.size() > 0) { it = std::find(m_BackgroundRenderers.begin(),m_BackgroundRenderers.end(),renderer); if(it != m_BackgroundRenderers.end()) { m_BackgroundRenderers.erase(it); UpdateLayers(); return; } } // scene layers if(m_SceneRenderers.size() > 0) { it = std::find(m_SceneRenderers.begin(),m_SceneRenderers.end(),renderer); if(it != m_SceneRenderers.end()) { m_SceneRenderers.erase(it); UpdateLayers(); return; } } // foreground layers if(m_ForegroundRenderers.size() > 0 ) { it = std::find(m_ForegroundRenderers.begin(),m_ForegroundRenderers.end(),renderer); if(it != m_ForegroundRenderers.end()) { m_ForegroundRenderers.erase(it); UpdateLayers(); return; } } } /** * Connects a VtkRenderWindow with the layer controller. */ -void mitk::VtkLayerController::SetRenderWindow(vtkRenderWindow* renwin) +void mitk::VtkLayerController::SetRenderWindow(vtkSmartPointer renwin) { if(renwin != NULL) { RendererVectorType::iterator it; // Tell all renderers that there is a new renderwindow for(it = m_BackgroundRenderers.begin(); it != m_BackgroundRenderers.end(); it++) { (*it)->SetRenderWindow(renwin); } for(it = m_SceneRenderers.begin(); it != m_SceneRenderers.end(); it++) { (*it)->SetRenderWindow(renwin); } for(it = m_ForegroundRenderers.begin(); it != m_ForegroundRenderers.end(); it++) { (*it)->SetRenderWindow(renwin); } // Set the new RenderWindow m_RenderWindow = renwin; } // Now sort renderers and add them to the renderwindow UpdateLayers(); } /** * Returns true if a renderer has been inserted */ -bool mitk::VtkLayerController::IsRendererInserted(vtkRenderer* renderer) +bool mitk::VtkLayerController::IsRendererInserted(vtkSmartPointer renderer) { RendererVectorType::iterator it; // background layers if(m_BackgroundRenderers.size() > 0) { it = std::find(m_BackgroundRenderers.begin(),m_BackgroundRenderers.end(),renderer); if ( it != m_BackgroundRenderers.end() ) { return true; } } // scene layers if(m_SceneRenderers.size() > 0) { it = std::find(m_SceneRenderers.begin(),m_SceneRenderers.end(),renderer); if ( it != m_SceneRenderers.end() ) { return true; } } // foreground layers if(m_ForegroundRenderers.size() > 0 ) { it = std::find(m_ForegroundRenderers.begin(),m_ForegroundRenderers.end(),renderer); if ( it != m_ForegroundRenderers.end() ) { return true; } } return false; } /** * Internally used to sort all registered renderers and to connect the with the vtkRenderWindow. * Mention that VTK Version 5 and above is rendering higher numbers in the background and VTK * Verison < 5 in the foreground. */ void mitk::VtkLayerController::UpdateLayers() { // Remove all Renderers from renderwindow - vtkRendererCollection* v = m_RenderWindow->GetRenderers(); + vtkSmartPointer v = m_RenderWindow->GetRenderers(); v->RemoveAllItems(); unsigned int numberOfLayers = static_cast(m_BackgroundRenderers.size() + m_SceneRenderers.size() + m_ForegroundRenderers.size()); int currentLayerNumber; bool traverseUpwards; currentLayerNumber = 0; traverseUpwards = true; m_RenderWindow->SetNumberOfLayers(numberOfLayers); RendererVectorType::iterator it; // assign a layer number for the backround renderers for(it = m_BackgroundRenderers.begin(); it != m_BackgroundRenderers.end(); it++) { (*it)->SetRenderWindow(m_RenderWindow); (*it)->SetLayer(currentLayerNumber); m_RenderWindow->AddRenderer((*it)); if(traverseUpwards) currentLayerNumber++; else currentLayerNumber--; } // assign a layer number for the scene renderers for(it = m_SceneRenderers.begin(); it != m_SceneRenderers.end(); it++) { (*it)->SetRenderWindow(m_RenderWindow); (*it)->SetLayer(currentLayerNumber); m_RenderWindow->AddRenderer((*it)); if(traverseUpwards) currentLayerNumber++; else currentLayerNumber--; } // assign a layer number for the foreground renderers for(it = m_ForegroundRenderers.begin(); it != m_ForegroundRenderers.end(); it++) { (*it)->SetRenderWindow(m_RenderWindow); (*it)->SetLayer(currentLayerNumber); m_RenderWindow->AddRenderer((*it)); if(traverseUpwards) currentLayerNumber++; else currentLayerNumber--; } } /** * Returns the number of renderers in the renderwindow. */ unsigned int mitk::VtkLayerController::GetNumberOfRenderers() { return static_cast(m_BackgroundRenderers.size() + m_SceneRenderers.size() + m_ForegroundRenderers.size()); } void mitk::VtkLayerController::SetEraseForAllRenderers(int i) { - this->m_RenderWindow->SetErase(i); RendererVectorType::iterator it; for(it = m_BackgroundRenderers.begin(); it != m_BackgroundRenderers.end(); it++) (*it)->SetErase(i); for(it = m_SceneRenderers.begin(); it != m_SceneRenderers.end(); it++) (*it)->SetErase(i); for(it = m_ForegroundRenderers.begin(); it != m_ForegroundRenderers.end(); it++) (*it)->SetErase(i); - } - diff --git a/Core/Code/Controllers/mitkVtkLayerController.h b/Core/Code/Controllers/mitkVtkLayerController.h index 7b98c35de4..3f86f28cd5 100644 --- a/Core/Code/Controllers/mitkVtkLayerController.h +++ b/Core/Code/Controllers/mitkVtkLayerController.h @@ -1,134 +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. ===================================================================*/ -#ifndef MITKVTKLAYERCONTROLLER_H_HEADER_INCLUDED_C1EDO02D -#define MITKVTKLAYERCONTROLLER_H_HEADER_INCLUDED_C1EDO02D +#ifndef mitkVtkLayerController_h +#define mitkVtkLayerController_h #include #include #include +#include class vtkRenderWindow; class vtkRenderer; namespace mitk { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4251) #endif /** * Manages the VTK layer hierarchy * of a vtkRenderWindow. * For simple access the layers are divided into three * main groups: background, scene and foreground layers. * Renderers can be registered via the insert... functions and * removed via the RemoveRenderer function. */ class MITK_CORE_EXPORT VtkLayerController { public: - static VtkLayerController* GetInstance(vtkRenderWindow* renWin); - static void AddInstance(vtkRenderWindow* renWin, vtkRenderer * mitkSceneRenderer); - static void RemoveInstance(vtkRenderWindow* renWin); + static VtkLayerController* GetInstance(vtkSmartPointer renWin); + static void AddInstance(vtkSmartPointer renWin, vtkSmartPointer mitkSceneRenderer); + static void RemoveInstance(vtkSmartPointer renWin); - VtkLayerController(vtkRenderWindow* renderWindow); + VtkLayerController(vtkSmartPointer renderWindow); virtual ~VtkLayerController(); /** * Returns the current vtkRenderer of the Scene */ - vtkRenderer* GetSceneRenderer(); + vtkSmartPointer GetSceneRenderer(); /** * Connects a VTK renderer with a vtk renderwindow. The renderer will be rendered in the background. * With forceAbsoluteBackground set true a renderer can be placed at the absolute background of the scene. * Multiple calls with forceAbsoluteBackground set true will set the latest registered renderer as background. */ - void InsertBackgroundRenderer(vtkRenderer* renderer, bool forceAbsoluteBackground); + void InsertBackgroundRenderer(vtkSmartPointer renderer, bool forceAbsoluteBackground); /** * Connects a VTK renderer with a vtk renderwindow. The renderer will be rendered in the foreground. * With forceAbsoluteBackground set true a renderer can be placed at the absolute foreground of the scene. * Multiple calls with forceAbsoluteForeground set true will set the latest registered renderer as foreground. */ - void InsertForegroundRenderer(vtkRenderer* renderer, bool forceAbsoluteForeground); + void InsertForegroundRenderer(vtkSmartPointer renderer, bool forceAbsoluteForeground); /** * Connects a VTK renderer with a vtk renderwindow. The renderer will be rendered between background renderers and * foreground renderers. */ - void InsertSceneRenderer(vtkRenderer* renderer); + void InsertSceneRenderer(vtkSmartPointer renderer); /** * Connects a VtkRenderWindow with the layer controller. */ - void SetRenderWindow(vtkRenderWindow* renwin); + void SetRenderWindow(vtkSmartPointer renwin); /** * A renderer which has been inserted via a insert... function can be removed from the vtkRenderWindow with * RemoveRenderer. */ - void RemoveRenderer(vtkRenderer* renderer); + void RemoveRenderer(vtkSmartPointer renderer); /** * Returns true if a renderer has been inserted */ - bool IsRendererInserted(vtkRenderer* renderer); + bool IsRendererInserted(vtkSmartPointer renderer); /** * Returns the number of renderers in the renderwindow. */ unsigned int GetNumberOfRenderers(); void SetEraseForAllRenderers(int i); protected: - vtkRenderWindow* m_RenderWindow; + vtkSmartPointer m_RenderWindow; private: /** * Internally used to sort all registered renderers and to connect the with the vtkRenderWindow. * Mention that VTK Version 5 and above is rendering higher numbers in the background and VTK * Verison < 5 in the foreground. */ void UpdateLayers(); // Layer Management - typedef std::vector RendererVectorType; + typedef std::vector< vtkSmartPointer > RendererVectorType; RendererVectorType m_BackgroundRenderers; RendererVectorType m_SceneRenderers; RendererVectorType m_ForegroundRenderers; - typedef std::map vtkLayerControllerMapType; + typedef std::map,mitk::VtkLayerController*> vtkLayerControllerMapType; static vtkLayerControllerMapType s_LayerControllerMap; }; #ifdef _MSC_VER # pragma warning(pop) #endif } // Namespace MITK - - - -#endif /* MITKVTKLAYERCONTROLLER_H_HEADER_INCLUDED_C1EDO02D */ - - +#endif /* mitkVtkLayerController_h */ diff --git a/Core/Code/Rendering/mitkRenderWindowFrame.cpp b/Core/Code/Rendering/mitkRenderWindowFrame.cpp index 018b91522f..4b6bf77db3 100644 --- a/Core/Code/Rendering/mitkRenderWindowFrame.cpp +++ b/Core/Code/Rendering/mitkRenderWindowFrame.cpp @@ -1,143 +1,111 @@ /*=================================================================== 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 "mitkRenderWindowFrame.h" #include "mitkVtkLayerController.h" #include "vtkMitkRectangleProp.h" -#include -#include -#include -#include -#include - #include #include -#include -#include mitk::RenderWindowFrame::RenderWindowFrame() { m_RenderWindow = NULL; - m_RectangleRenderer = vtkRenderer::New(); + m_RectangleRenderer = vtkSmartPointer::New(); m_IsEnabled = false; } mitk::RenderWindowFrame::~RenderWindowFrame() { if ( m_RenderWindow != NULL ) if ( this->IsEnabled() ) this->Disable(); - - if ( m_RectangleRenderer != NULL ) - m_RectangleRenderer->Delete(); } /** * Sets the renderwindow, in which the text * will be shown. Make sure, you have called this function * before calling Enable() */ -void mitk::RenderWindowFrame::SetRenderWindow( vtkRenderWindow* renderWindow ) +void mitk::RenderWindowFrame::SetRenderWindow(vtkSmartPointer renderWindow ) { m_RenderWindow = renderWindow; } /** * Returns the vtkRenderWindow, which is used * for displaying the text */ -vtkRenderWindow* mitk::RenderWindowFrame::GetRenderWindow() +vtkSmartPointer mitk::RenderWindowFrame::GetRenderWindow() { return m_RenderWindow; } /** * Returns the renderer responsible for * rendering the text into the * vtkRenderWindow */ -vtkRenderer* mitk::RenderWindowFrame::GetVtkRenderer() +vtkSmartPointer mitk::RenderWindowFrame::GetVtkRenderer() { return m_RectangleRenderer; } /** * Disables drawing of the text label collection. * If you want to enable it, call the Enable() function. */ void mitk::RenderWindowFrame::Disable() { if ( this->IsEnabled()) { m_RectangleRenderer->EraseOn(); mitk::VtkLayerController::GetInstance(m_RenderWindow)->RemoveRenderer(m_RectangleRenderer); m_IsEnabled = false; } } /** * Enables drawing of the text label collection. * If you want to disable it, call the Disable() function. */ void mitk::RenderWindowFrame::Enable(float col1, float col2, float col3) { vtkSmartPointer rect = vtkSmartPointer::New(); rect->SetRenderWindow(m_RenderWindow); rect->SetColor(col1, col2, col3); m_RectangleRenderer->AddActor(rect); if(!mitk::VtkLayerController::GetInstance(m_RenderWindow)->IsRendererInserted( m_RectangleRenderer )) { m_RectangleRenderer->EraseOff(); m_RectangleRenderer->SetInteractive(0); mitk::VtkLayerController::GetInstance(m_RenderWindow)->InsertForegroundRenderer(m_RectangleRenderer,true); m_IsEnabled = true; } } /** * Checks, if the text is currently * enabled (visible) */ bool mitk::RenderWindowFrame::IsEnabled() { return m_IsEnabled; } - -void mitk::RenderWindowFrame::SetRequestedRegionToLargestPossibleRegion() -{ - //nothing to do -} - -bool mitk::RenderWindowFrame::RequestedRegionIsOutsideOfTheBufferedRegion() -{ - return false; -} - -bool mitk::RenderWindowFrame::VerifyRequestedRegion() -{ - return true; -} - -void mitk::RenderWindowFrame::SetRequestedRegion( const itk::DataObject*) -{ - //nothing to do -} - diff --git a/Core/Code/Rendering/mitkRenderWindowFrame.h b/Core/Code/Rendering/mitkRenderWindowFrame.h index 49d45d56c7..0fe704f0b8 100644 --- a/Core/Code/Rendering/mitkRenderWindowFrame.h +++ b/Core/Code/Rendering/mitkRenderWindowFrame.h @@ -1,133 +1,104 @@ /*=================================================================== 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_Colored_Rectangle_Rendering_h_ -#define _vtk_Colored_Rectangle_Rendering_h_ +#ifndef mitkRenderWindowFrame_h +#define mitkRenderWindowFrame_h - -#include +#include +#include +#include #include -#include -#include - class vtkRenderer; class vtkRenderWindow; -class vtkCamera; -class vtkTextProperty; -class vtkTextActor; namespace mitk { /** * This is a simple class for rendering colored rectangles * at the boarders of vtkRenderWindows. * The rectangle rendering itself is performed by means of a * vtkProp (vtkMitkRectangleProp). * This class instantiates the vtkProp and a corresponding vtkRenderer instance. */ -class MITK_CORE_EXPORT RenderWindowFrame : public BaseData +class MITK_CORE_EXPORT RenderWindowFrame : public itk::Object { public: - mitkClassMacro( RenderWindowFrame, BaseData ); + mitkClassMacro( RenderWindowFrame, itk::Object ); itkFactorylessNewMacro(Self) itkCloneMacro(Self) /** * Sets the renderwindow, in which colored rectangle boarders will be shown. * Make sure, you have called this function * before calling Enable() */ - virtual void SetRenderWindow( vtkRenderWindow* renderWindow ); + virtual void SetRenderWindow( vtkSmartPointer renderWindow ); /** * Enables drawing of the colored rectangle. * If you want to disable it, call the Disable() function. */ virtual void Enable(float col1, float col2, float col3); /** * Disables drawing of the colored rectangle. * If you want to enable it, call the Enable() function. */ virtual void Disable(); /** * Checks, if the text is currently * enabled (visible) */ virtual bool IsEnabled(); - /** - * Empty implementation, since the rectangle rendering doesn't - * support the requested region concept - */ - virtual void SetRequestedRegionToLargestPossibleRegion(); - - /** - * Empty implementation, since the rectangle rendering doesn't - * support the requested region concept - */ - virtual bool RequestedRegionIsOutsideOfTheBufferedRegion(); - - /** - * Empty implementation, since the rectangle rendering doesn't - * support the requested region concept - */ - virtual bool VerifyRequestedRegion(); - - /** - * Empty implementation, since the rectangle rendering doesn't - * support the requested region concept - */ - virtual void SetRequestedRegion( const itk::DataObject*); - /** * Returns the vtkRenderWindow, which is used * for displaying the text */ - virtual vtkRenderWindow* GetRenderWindow(); + virtual vtkSmartPointer GetRenderWindow(); /** * Returns the renderer responsible for * rendering the text into the * vtkRenderWindow */ - virtual vtkRenderer* GetVtkRenderer(); + virtual vtkSmartPointer GetVtkRenderer(); protected: /** * Constructor */ RenderWindowFrame(); /** * Destructor */ ~RenderWindowFrame(); - vtkRenderWindow* m_RenderWindow; - vtkRenderer* m_RectangleRenderer; + vtkSmartPointer m_RenderWindow; + vtkSmartPointer m_RectangleRenderer; bool m_IsEnabled; }; } //end of namespace mitk -#endif +#endif //mitkRenderWindowFrame_h diff --git a/Core/Code/Rendering/vtkMitkRectangleProp.cpp b/Core/Code/Rendering/vtkMitkRectangleProp.cpp index 8ff8692083..bdd5c41169 100644 --- a/Core/Code/Rendering/vtkMitkRectangleProp.cpp +++ b/Core/Code/Rendering/vtkMitkRectangleProp.cpp @@ -1,116 +1,116 @@ /*=================================================================== 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 "vtkMitkRectangleProp.h" #include #include #include #include #include #include #include #include #include vtkStandardNewMacro(vtkMitkRectangleProp); vtkMitkRectangleProp::vtkMitkRectangleProp() { vtkSmartPointer mapper = vtkSmartPointer::New(); m_RectangleActor = vtkSmartPointer::New(); m_PolyData = vtkSmartPointer::New(); vtkSmartPointer lines = vtkSmartPointer::New(); vtkSmartPointer points = vtkSmartPointer::New(); m_PolyData->SetPoints(points); m_PolyData->SetLines(lines); this->CreateRectangle(); mapper->SetInputData(m_PolyData); m_RectangleActor->SetMapper(mapper); } vtkMitkRectangleProp::~vtkMitkRectangleProp() { } int vtkMitkRectangleProp::RenderOverlay(vtkViewport* viewport) { double right = m_RenderWindow->GetSize()[0]; double top = m_RenderWindow->GetSize()[1]; double bottom = 0.5; double left = 0.5; double defaultDepth = 0.0; vtkSmartPointer points = m_PolyData->GetPoints(); //change the corners to adapt the size of the renderwindow was resized points->SetPoint(m_BottomLeft, left, bottom, defaultDepth); points->SetPoint(m_TopLeft, left, top, defaultDepth); points->SetPoint(m_TopRight, right, top, defaultDepth); points->SetPoint(m_BottomRight, right, bottom, defaultDepth); //adapt color m_RectangleActor->GetProperty()->SetColor( m_Color[0], m_Color[1], m_Color[2]); //render the actor m_RectangleActor->RenderOverlay(viewport); return 1; } void vtkMitkRectangleProp::CreateRectangle() { vtkSmartPointer points = m_PolyData->GetPoints(); vtkSmartPointer lines = m_PolyData->GetLines(); double bottom = 0.5; double left = 0.5; double right = 199.0; double top = 199.0; double defaultDepth = 0.0; //4 corner points m_BottomLeft = points->InsertNextPoint(left, bottom, defaultDepth); m_BottomRight = points->InsertNextPoint(right, bottom, defaultDepth); m_TopLeft = points->InsertNextPoint(left, top, defaultDepth); m_TopRight = points->InsertNextPoint(right, top, defaultDepth); vtkSmartPointer lineVtk = vtkSmartPointer::New(); lineVtk->GetPointIds()->SetNumberOfIds(5); //connect the lines lineVtk->GetPointIds()->SetId(0,m_BottomLeft); lineVtk->GetPointIds()->SetId(1,m_BottomRight); lineVtk->GetPointIds()->SetId(2,m_TopRight); lineVtk->GetPointIds()->SetId(3,m_TopLeft); lineVtk->GetPointIds()->SetId(4,m_BottomLeft); lines->InsertNextCell(lineVtk); } -void vtkMitkRectangleProp::SetRenderWindow(vtkRenderWindow* renWin) +void vtkMitkRectangleProp::SetRenderWindow(vtkSmartPointer renWin) { m_RenderWindow = renWin; } void vtkMitkRectangleProp::SetColor(float col1, float col2, float col3) { m_Color[0] = col1; m_Color[1] = col2; m_Color[2] = col3; } diff --git a/Core/Code/Rendering/vtkMitkRectangleProp.h b/Core/Code/Rendering/vtkMitkRectangleProp.h index 9adbc71dbe..a67200f532 100644 --- a/Core/Code/Rendering/vtkMitkRectangleProp.h +++ b/Core/Code/Rendering/vtkMitkRectangleProp.h @@ -1,95 +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 vtkMitkRectangleProp2_h -#define vtkMitkRectangleProp2_h +#ifndef vtkMitkRectangleProp_h +#define vtkMitkRectangleProp_h #include #include #include #include class vtkActor2D; class vtkPolyData; /** * @brief The vtkMitkRectangleProp2 class Renders a rectangle into a renderwindow as a frame. * * This class is a replacement for the deprecated vtkMitkRectangleProp, which * used to render the same effect with pure OpenGL. */ class MITK_EXPORT vtkMitkRectangleProp : public vtkProp { public: static vtkMitkRectangleProp* New(); vtkTypeMacro(vtkMitkRectangleProp,vtkProp); /** * @brief RenderOverlay Calls the render method of the actor and renders it. * @param viewport viewport of the renderwindow. * @return */ int RenderOverlay(vtkViewport* viewport); /** * @brief SetRenderWindow Set the renderwindow. * @param renWin */ - void SetRenderWindow(vtkRenderWindow* renWin); + void SetRenderWindow(vtkSmartPointer renWin); /** * @brief SetColor Set the color of the rectangle. * @param col1 red * @param col2 green * @param col3 blue */ void SetColor(float col1, float col2, float col3); protected: vtkMitkRectangleProp(); virtual ~vtkMitkRectangleProp(); /** * @brief m_RenderWindow renderwindow to add the rectangle to. */ - vtkRenderWindow* m_RenderWindow; + vtkSmartPointer m_RenderWindow; /** * @brief m_Color color of thr rectangle. */ float m_Color[3]; /** * @brief CreateRectangle internal helper to fill a vtkPolydata with a rectangle. */ void CreateRectangle(); /** * @brief m_PolyData holds the rectangle. */ vtkSmartPointer m_PolyData; /** * @brief m_RectangleActor actor to render the rectangle. */ vtkSmartPointer m_RectangleActor; /** * @brief IDs of the corner points (the corners of the renderwindow). */ vtkIdType m_BottomLeft, m_BottomRight, m_TopRight, m_TopLeft; }; -#endif /* vtkMitkRectangleProp2_h */ +#endif /* vtkMitkRectangleProp_h */ diff --git a/Core/Code/Testing/mitkDataNodeTest.cpp b/Core/Code/Testing/mitkDataNodeTest.cpp index b504a3fdb6..26de8b7e64 100644 --- a/Core/Code/Testing/mitkDataNodeTest.cpp +++ b/Core/Code/Testing/mitkDataNodeTest.cpp @@ -1,297 +1,291 @@ /*=================================================================== 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 "mitkDataNode.h" #include #include "mitkVtkPropRenderer.h" #include "mitkTestingMacros.h" #include "mitkGlobalInteraction.h" #include //Basedata Test -#include #include #include #include #include #include #include #include //Mapper Test //#include #include //#include #include #include #include #include #include //Interactors #include //Propertylist Test /** * Simple example for a test for the (non-existent) class "DataNode". * * argc and argv are the command line parameters which were passed to * the ADD_TEST command in the CMakeLists.txt file. For the automatic * tests, argv is either empty for the simple tests or contains the filename * of a test image for the image tests (see CMakeLists.txt). */ class mitkDataNodeTestClass { public: static void TestDataSetting(mitk::DataNode::Pointer dataNode) { mitk::BaseData::Pointer baseData; //NULL pointer Test dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a NULL pointer was set correctly" ) - baseData = mitk::RenderWindowFrame::New(); - dataNode->SetData(baseData); - MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a RenderWindowFrame object was set correctly" ) -// MITK_TEST_CONDITION( baseData->GetGeometry(0)->GetVtkTransform() == dataNode->GetVtkTransform(0), "Testing if a NULL pointer was set correctly" ) - baseData = mitk::GeometryData::New(); dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a GeometryData object was set correctly" ) baseData = mitk::PlaneGeometryData::New(); dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a PlaneGeometryData object was set correctly" ) baseData = mitk::GradientBackground::New(); dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a GradientBackground object was set correctly" ) baseData = mitk::ManufacturerLogo::New(); dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a ManufacturerLogo object was set correctly" ) baseData = mitk::PointSet::New(); dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a PointSet object was set correctly" ) baseData = mitk::Image::New(); dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a Image object was set correctly" ) baseData = mitk::Surface::New(); dataNode->SetData(baseData); MITK_TEST_CONDITION( baseData == dataNode->GetData(), "Testing if a Surface object was set correctly" ) } static void TestMapperSetting(mitk::DataNode::Pointer dataNode) { //tests the SetMapper() method //in dataNode is a mapper vector which can be accessed by index //in this test method we use only slot 0 (filled with null) and slot 1 //so we also test the destructor of the mapper classes mitk::Mapper::Pointer mapper; dataNode->SetMapper(0,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(0), "Testing if a NULL pointer was set correctly" ) // mapper = mitk::PlaneGeometryDataMapper2D::New(); // dataNode->SetMapper(1,mapper); // MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a PlaneGeometryDataMapper2D was set correctly" ) // MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) mapper = mitk::ImageVtkMapper2D::New(); dataNode->SetMapper(1,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a ImageVtkMapper2D was set correctly" ) MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) mapper = mitk::PointSetVtkMapper2D::New(); dataNode->SetMapper(1,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a PointSetVtkMapper2D was set correctly" ) MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) // mapper = mitk::SurfaceGLMapper2D::New(); // dataNode->SetMapper(1,mapper); // MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a SurfaceGLMapper2D was set correctly" ) // MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) mapper = mitk::PlaneGeometryDataVtkMapper3D::New(); dataNode->SetMapper(1,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a PlaneGeometryDataVtkMapper3D was set correctly" ) MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) mapper = mitk::PointSetVtkMapper3D::New(); dataNode->SetMapper(1,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a PointSetVtkMapper3D was set correctly" ) MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) mapper = mitk::SurfaceVtkMapper3D::New(); dataNode->SetMapper(1,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a SurfaceVtkMapper3D was set correctly" ) MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) mapper = mitk::VolumeDataVtkMapper3D::New(); dataNode->SetMapper(1,mapper); MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a VolumeDataVtkMapper3D was set correctly" ) MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) //linker error //mapper = mitk::LineVtkMapper3D::New(); //dataNode->SetMapper(1,mapper); //MITK_TEST_CONDITION( mapper == dataNode->GetMapper(1), "Testing if a LineVtkMapper3D was set correctly" ) //MITK_TEST_CONDITION( dataNode == mapper->GetDataNode(), "Testing if the mapper returns the right DataNode" ) } static void TestInteractorSetting(mitk::DataNode::Pointer dataNode) { //this method tests the SetInteractor() and GetInteractor methods //the DataInteractor base class calls the DataNode->SetInteractor method mitk::DataInteractor::Pointer interactor; MITK_TEST_CONDITION( interactor == dataNode->GetDataInteractor(), "Testing if a NULL pointer was set correctly (DataInteractor)" ) interactor = mitk::PointSetDataInteractor::New(); interactor->SetEventConfig("PointSetConfig.xml"); interactor->SetDataNode(dataNode); MITK_TEST_CONDITION( interactor == dataNode->GetDataInteractor(), "Testing if a PointSetDataInteractor was set correctly" ) interactor = mitk::PointSetDataInteractor::New(); dataNode->SetDataInteractor(interactor); MITK_TEST_CONDITION( interactor == dataNode->GetDataInteractor(), "Testing if a PointSetDataInteractor was set correctly" ) } static void TestPropertyList(mitk::DataNode::Pointer dataNode) { mitk::PropertyList::Pointer propertyList = dataNode->GetPropertyList(); MITK_TEST_CONDITION(dataNode->GetPropertyList() != NULL, "Testing if the constructor set the propertylist" ) dataNode->SetIntProperty("int", -31337); int x; dataNode->GetIntProperty("int", x); MITK_TEST_CONDITION(x == -31337, "Testing Set/GetIntProperty"); dataNode->SetBoolProperty("bool", true); bool b; dataNode->GetBoolProperty("bool", b); MITK_TEST_CONDITION(b == true, "Testing Set/GetBoolProperty"); dataNode->SetFloatProperty("float", -31.337); float y; dataNode->GetFloatProperty("float", y); MITK_TEST_CONDITION(y - -31.337 < 0.01, "Testing Set/GetFloatProperty"); double yd = 0; dataNode->GetDoubleProperty("float", yd); MITK_TEST_CONDITION(mitk::Equal(yd, static_cast(y)), "Testing GetDoubleProperty"); dataNode->SetStringProperty("string", "MITK"); std::string s = "GANZVIELPLATZ"; dataNode->GetStringProperty("string", s); MITK_TEST_CONDITION(s == "MITK", "Testing Set/GetStringProperty"); std::string name = "MyTestName"; dataNode->SetName(name.c_str()); MITK_TEST_CONDITION(dataNode->GetName() == name, "Testing Set/GetName"); name = "MySecondTestName"; dataNode->SetName(name); MITK_TEST_CONDITION(dataNode->GetName() == name, "Testing Set/GetName(std::string)"); MITK_TEST_CONDITION(propertyList == dataNode->GetPropertyList(), "Testing if the propertylist has changed during the last tests" ) } static void TestSelected(mitk::DataNode::Pointer dataNode) { vtkRenderWindow *renderWindow = vtkRenderWindow::New(); mitk::VtkPropRenderer::Pointer base = mitk::VtkPropRenderer::New( "the first renderer", renderWindow, mitk::RenderingManager::GetInstance() ); //with BaseRenderer==Null MITK_TEST_CONDITION(!dataNode->IsSelected(), "Testing if this node is not set as selected" ) dataNode->SetSelected(true); MITK_TEST_CONDITION(dataNode->IsSelected(), "Testing if this node is set as selected" ) dataNode->SetSelected(false); dataNode->SetSelected(true,base); MITK_TEST_CONDITION(dataNode->IsSelected(base), "Testing if this node with right base renderer is set as selected" ) //Delete RenderWindow correctly renderWindow->Delete(); } static void TestGetMTime(mitk::DataNode::Pointer dataNode) { unsigned long time; time = dataNode->GetMTime(); mitk::PointSet::Pointer pointSet = mitk::PointSet::New(); dataNode->SetData(pointSet); MITK_TEST_CONDITION( time != dataNode->GetMTime(), "Testing if the node timestamp is updated after adding data to the node" ) mitk::Point3D point; point.Fill(3.0); pointSet->SetPoint(0,point); //less or equal because dataNode timestamp is little later then the basedata timestamp MITK_TEST_CONDITION( pointSet->GetMTime() <= dataNode->GetMTime(), "Testing if the node timestamp is updated after base data was modified" ) // testing if changing anything in the property list also sets the node in a modified state unsigned long lastModified = dataNode->GetMTime(); dataNode->SetIntProperty("testIntProp", 2344); MITK_TEST_CONDITION( lastModified <= dataNode->GetMTime(), "Testing if the node timestamp is updated after property list was modified" ) } }; //mitkDataNodeTestClass int mitkDataNodeTest(int /* argc */, char* /*argv*/[]) { // always start with this! MITK_TEST_BEGIN("DataNode") // Global interaction must(!) be initialized mitk::GlobalInteraction::GetInstance()->Initialize("global"); // let's create an object of our class mitk::DataNode::Pointer myDataNode = mitk::DataNode::New(); // first test: did this work? // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since // it makes no sense to continue without an object. MITK_TEST_CONDITION_REQUIRED(myDataNode.IsNotNull(),"Testing instantiation") //test setData() Method mitkDataNodeTestClass::TestDataSetting(myDataNode); mitkDataNodeTestClass::TestMapperSetting(myDataNode); // //note, that no data is set to the dataNode mitkDataNodeTestClass::TestInteractorSetting(myDataNode); mitkDataNodeTestClass::TestPropertyList(myDataNode); mitkDataNodeTestClass::TestSelected(myDataNode); mitkDataNodeTestClass::TestGetMTime(myDataNode); // write your own tests here and use the macros from mitkTestingMacros.h !!! // do not write to std::cout and do not return from this function yourself! // always end with this! MITK_TEST_END() }