diff --git a/Core/Code/Rendering/mitkSurfaceVtkMapper2D.cpp b/Core/Code/Rendering/mitkSurfaceVtkMapper2D.cpp index 5d8690e5b4..2f0b9e40f7 100644 --- a/Core/Code/Rendering/mitkSurfaceVtkMapper2D.cpp +++ b/Core/Code/Rendering/mitkSurfaceVtkMapper2D.cpp @@ -1,289 +1,289 @@ /*=================================================================== 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 "mitkSurfaceVtkMapper2D.h" //mitk includes #include #include #include "mitkVtkPropRenderer.h" #include #include #include //vtk includes #include #include #include #include #include #include #include #include #include #include // constructor LocalStorage mitk::SurfaceVtkMapper2D::LocalStorage::LocalStorage() { m_Mapper = vtkSmartPointer::New(); m_Mapper->ScalarVisibilityOff(); m_Actor = vtkSmartPointer::New(); m_Actor->SetMapper( m_Mapper ); m_PropAssembly = vtkSmartPointer ::New(); m_PropAssembly->AddPart( m_Actor ); m_CuttingPlane = vtkSmartPointer::New(); m_Cutter = vtkSmartPointer::New(); m_Cutter->SetCutFunction(m_CuttingPlane); m_Mapper->SetInputConnection( m_Cutter->GetOutputPort() ); } // destructor LocalStorage mitk::SurfaceVtkMapper2D::LocalStorage::~LocalStorage() { } const mitk::Surface* mitk::SurfaceVtkMapper2D::GetInput() const { return static_cast ( GetDataNode()->GetData() ); } // constructor PointSetVtkMapper2D mitk::SurfaceVtkMapper2D::SurfaceVtkMapper2D() : m_DrawNormals(false), m_FrontNormalLengthInPixels(10.0), m_BackNormalLengthInPixels(10.0) - { - // default for normals on front side = green - m_FrontSideColor[0] = 0.0; - m_FrontSideColor[1] = 1.0; - m_FrontSideColor[2] = 0.0; - m_FrontSideColor[3] = 1.0; - - // default for normals on back side = red - m_BackSideColor[0] = 1.0; - m_BackSideColor[1] = 0.0; - m_BackSideColor[2] = 0.0; - m_BackSideColor[3] = 1.0; - - // default for line color = yellow - m_LineColor[0] = 1.0; - m_LineColor[1] = 1.0; - m_LineColor[2] = 0.0; - m_LineColor[3] = 1.0; +{ + // default for normals on front side = green + m_FrontSideColor[0] = 0.0; + m_FrontSideColor[1] = 1.0; + m_FrontSideColor[2] = 0.0; + m_FrontSideColor[3] = 1.0; + + // default for normals on back side = red + m_BackSideColor[0] = 1.0; + m_BackSideColor[1] = 0.0; + m_BackSideColor[2] = 0.0; + m_BackSideColor[3] = 1.0; + + // default for line color = yellow + m_LineColor[0] = 1.0; + m_LineColor[1] = 1.0; + m_LineColor[2] = 0.0; + m_LineColor[3] = 1.0; } mitk::SurfaceVtkMapper2D::~SurfaceVtkMapper2D() { } // reset mapper so that nothing is displayed e.g. toggle visiblity of the propassembly void mitk::SurfaceVtkMapper2D::ResetMapper( BaseRenderer* renderer ) { LocalStorage *ls = m_LSH.GetLocalStorage(renderer); ls->m_PropAssembly->VisibilityOff(); } vtkProp* mitk::SurfaceVtkMapper2D::GetVtkProp(mitk::BaseRenderer * renderer) { LocalStorage *ls = m_LSH.GetLocalStorage(renderer); return ls->m_PropAssembly; } void mitk::SurfaceVtkMapper2D::Update(mitk::BaseRenderer* renderer) { const mitk::DataNode* node = GetDataNode(); if( node == NULL ) return; bool visible = true; node->GetVisibility(visible, renderer, "visible"); if ( !visible ) { return; } mitk::Surface* surface = static_cast( node->GetData() ); if ( surface == NULL ) { return; } // Calculate time step of the input data for the specified renderer (integer value) this->CalculateTimeStep( renderer ); // Check if time step is valid const mitk::TimeGeometry *dataTimeGeometry = surface->GetTimeGeometry(); if ( ( dataTimeGeometry == NULL ) || ( dataTimeGeometry->CountTimeSteps() == 0 ) || ( !dataTimeGeometry->IsValidTimeStep( this->GetTimestep() ) ) ) { return; } surface->UpdateOutputInformation(); LocalStorage* localStorage = m_LSH.GetLocalStorage(renderer); //check if something important has changed and we need to rerender if ( (localStorage->m_LastUpdateTime < node->GetMTime()) //was the node modified? || (localStorage->m_LastUpdateTime < surface->GetPipelineMTime()) //Was the data modified? || (localStorage->m_LastUpdateTime < renderer->GetCurrentWorldPlaneGeometryUpdateTime()) //was the geometry modified? || (localStorage->m_LastUpdateTime < renderer->GetCurrentWorldPlaneGeometry()->GetMTime()) || (localStorage->m_LastUpdateTime < node->GetPropertyList()->GetMTime()) //was a property modified? || (localStorage->m_LastUpdateTime < node->GetPropertyList(renderer)->GetMTime()) ) { this->GenerateDataForRenderer( renderer ); } // since we have checked that nothing important has changed, we can set // m_LastUpdateTime to the current time localStorage->m_LastUpdateTime.Modified(); } void mitk::SurfaceVtkMapper2D::GenerateDataForRenderer( mitk::BaseRenderer *renderer ) { const mitk::DataNode* node = GetDataNode(); mitk::Surface* surface = static_cast( node->GetData() ); const mitk::TimeGeometry *dataTimeGeometry = surface->GetTimeGeometry(); LocalStorage* localStorage = m_LSH.GetLocalStorage(renderer); ScalarType time =renderer->GetTime(); int timestep=0; if( time > itk::NumericTraits::NonpositiveMin() ) timestep = dataTimeGeometry->TimePointToTimeStep( time ); vtkSmartPointer inputPolyData = surface->GetVtkPolyData( timestep ); if((inputPolyData==NULL) || (inputPolyData->GetNumberOfPoints() < 1 )) return; //apply color and opacity read from the PropertyList this->ApplyAllProperties(renderer); const PlaneGeometry* planeGeometry = renderer->GetCurrentWorldPlaneGeometry(); if( ( planeGeometry == NULL ) || ( !planeGeometry->IsValid() ) || ( !planeGeometry->HasReferenceGeometry() )) { return; } double origin[3]; origin[0] = planeGeometry->GetOrigin()[0]; origin[1] = planeGeometry->GetOrigin()[1]; origin[2] = planeGeometry->GetOrigin()[2]; double normal[3]; normal[0] = planeGeometry->GetNormal()[0]; normal[1] = planeGeometry->GetNormal()[1]; normal[2] = planeGeometry->GetNormal()[2]; localStorage->m_CuttingPlane->SetOrigin(origin); localStorage->m_CuttingPlane->SetNormal(normal); localStorage->m_Cutter->SetInputData(inputPolyData); localStorage->m_Cutter->Update(); //By default, the cutter will also copy/compute normals of the cut //to the output polydata. The normals will be rendered by the //vtkPolyDataMapper in a (weird) way. It seems that there is no way //to turn off that rendering or to stop the computation. Setting //the normals to NULL produces our desired (clean) output. localStorage->m_Cutter->GetOutput()->GetPointData()->SetNormals(NULL); -// vtkSmartPointer vtktmprenderer = vtkSmartPointer::New(); -// vtktmprenderer->AddActor(localStorage->m_Actor); //display the cube + // vtkSmartPointer vtktmprenderer = vtkSmartPointer::New(); + // vtktmprenderer->AddActor(localStorage->m_Actor); //display the cube -// //Add renderer to renderwindow and render -// vtkSmartPointer renderWindow = -// vtkSmartPointer::New(); -// renderWindow->AddRenderer(vtktmprenderer); -// renderWindow->SetSize(600, 600); + // //Add renderer to renderwindow and render + // vtkSmartPointer renderWindow = + // vtkSmartPointer::New(); + // renderWindow->AddRenderer(vtktmprenderer); + // renderWindow->SetSize(600, 600); -// vtkSmartPointer interactor = -// vtkSmartPointer::New(); -// interactor->SetRenderWindow(renderWindow); -// renderWindow->Render(); + // vtkSmartPointer interactor = + // vtkSmartPointer::New(); + // interactor->SetRenderWindow(renderWindow); + // renderWindow->Render(); -// interactor->Start(); + // interactor->Start(); } void mitk::SurfaceVtkMapper2D::ApplyAllProperties(mitk::BaseRenderer* renderer) { DataNode * node = GetDataNode(); if(node == NULL) { return; } node->GetBoolProperty("draw normals 2D", m_DrawNormals, renderer); float lineWidth = 1.0f; node->GetFloatProperty("line width", lineWidth, renderer); LocalStorage* localStorage = m_LSH.GetLocalStorage(renderer); // check for color and opacity properties, use it for rendering if they exists float color[3]= { 1.0f, 1.0f, 1.0f }; node->GetColor(color, renderer, "color"); float opacity = 1.0f; node->GetOpacity(opacity, renderer, "opacity"); localStorage->m_Actor->GetProperty()->SetColor(color[0], color[1], color[2]); localStorage->m_Actor->GetProperty()->SetOpacity(opacity); localStorage->m_Actor->GetProperty()->SetLineWidth(lineWidth); bool invertNormals(false); node->GetBoolProperty("invert normals", invertNormals, renderer); if (!invertNormals) { node->GetColor(m_FrontSideColor, renderer, "front color"); node->GetOpacity(m_FrontSideColor[3], renderer, "opacity"); node->GetColor(m_BackSideColor, renderer, "back color"); node->GetOpacity(m_BackSideColor[3], renderer, "opacity"); node->GetFloatProperty( "front normal lenth (px)", m_FrontNormalLengthInPixels, renderer ); node->GetFloatProperty( "back normal lenth (px)", m_BackNormalLengthInPixels, renderer ); } else { node->GetColor(m_FrontSideColor, renderer, "back color"); node->GetOpacity(m_FrontSideColor[3], renderer, "opacity"); node->GetColor(m_BackSideColor, renderer, "front color"); node->GetOpacity(m_BackSideColor[3], renderer, "opacity"); node->GetFloatProperty( "back normal lenth (px)", m_FrontNormalLengthInPixels, renderer ); node->GetFloatProperty( "front normal lenth (px)", m_BackNormalLengthInPixels, renderer ); } } void mitk::SurfaceVtkMapper2D::SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer, bool overwrite) { node->AddProperty( "line width", FloatProperty::New(2.0f), renderer, overwrite ); node->AddProperty( "scalar mode", VtkScalarModeProperty::New(), renderer, overwrite ); node->AddProperty( "draw normals 2D", BoolProperty::New(false), renderer, overwrite ); node->AddProperty( "invert normals", BoolProperty::New(false), renderer, overwrite ); node->AddProperty( "front color", ColorProperty::New(0.0, 1.0, 0.0), renderer, overwrite ); node->AddProperty( "back color", ColorProperty::New(1.0, 0.0, 0.0), renderer, overwrite ); node->AddProperty( "front normal lenth (px)", FloatProperty::New(10.0), renderer, overwrite ); node->AddProperty( "back normal lenth (px)", FloatProperty::New(10.0), renderer, overwrite ); node->AddProperty( "layer", IntProperty::New(100), renderer, overwrite); Superclass::SetDefaultProperties(node, renderer, overwrite); } diff --git a/Core/Code/Rendering/mitkSurfaceVtkMapper2D.h b/Core/Code/Rendering/mitkSurfaceVtkMapper2D.h index bd44f43ec5..b6a8d4561c 100644 --- a/Core/Code/Rendering/mitkSurfaceVtkMapper2D.h +++ b/Core/Code/Rendering/mitkSurfaceVtkMapper2D.h @@ -1,145 +1,145 @@ /*=================================================================== 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 mitkSurfaceVtkMapper2D_h #define mitkSurfaceVtkMapper2D_h #include #include "mitkVtkMapper.h" #include "mitkBaseRenderer.h" #include "mitkLocalStorageHandler.h" //VTK #include class vtkPropAssembly; class vtkCutter; class vtkPlane; class vtkLookupTable; namespace mitk { - class Surface; +class Surface; - /** +/** * @brief Vtk-based mapper for cutting 2D slices out of Surfaces. * @ingroup Mapper */ - class MITK_CORE_EXPORT SurfaceVtkMapper2D : public VtkMapper - { - public: - mitkClassMacro(SurfaceVtkMapper2D, VtkMapper); +class MITK_CORE_EXPORT SurfaceVtkMapper2D : public VtkMapper +{ +public: + mitkClassMacro(SurfaceVtkMapper2D, VtkMapper); - itkFactorylessNewMacro(Self) - itkCloneMacro(Self) + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) - virtual const mitk::Surface* GetInput() const; + virtual const mitk::Surface* GetInput() const; - /** \brief returns the prop assembly */ - virtual vtkProp* GetVtkProp(mitk::BaseRenderer* renderer); + /** \brief returns the prop assembly */ + virtual vtkProp* GetVtkProp(mitk::BaseRenderer* renderer); - /** \brief set the default properties for this mapper */ - static void SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer = NULL, bool overwrite = false); + /** \brief set the default properties for this mapper */ + static void SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer = NULL, bool overwrite = false); - /** \brief Internal class holding the mapper, actor, etc. for each of the 3 2D render windows */ - class LocalStorage : public mitk::Mapper::BaseLocalStorage - { - public: - /** \brief Timestamp of last update of stored data. */ - itk::TimeStamp m_LastUpdateTime; - /** + /** \brief Internal class holding the mapper, actor, etc. for each of the 3 2D render windows */ + class LocalStorage : public mitk::Mapper::BaseLocalStorage + { + public: + /** \brief Timestamp of last update of stored data. */ + itk::TimeStamp m_LastUpdateTime; + /** * @brief m_PropAssembly Contains all vtkProps for the final rendering. */ - vtkSmartPointer m_PropAssembly; - /** + vtkSmartPointer m_PropAssembly; + /** * \brief Actor of a 2D render window. */ - vtkSmartPointer m_Actor; - /** + vtkSmartPointer m_Actor; + /** * @brief m_Mapper VTK mapper for all types of 2D polydata e.g. werewolves. */ - vtkSmartPointer m_Mapper; - /** + vtkSmartPointer m_Mapper; + /** * @brief m_Cutter Filter to cut out the 2D slice. */ - vtkSmartPointer m_Cutter; - /** + vtkSmartPointer m_Cutter; + /** * @brief m_CuttingPlane The plane where to cut off the 2D slice. */ - vtkSmartPointer m_CuttingPlane; + vtkSmartPointer m_CuttingPlane; - /** \brief Default constructor of the local storage. */ - LocalStorage(); - /** \brief Default deconstructor of the local storage. */ - ~LocalStorage(); - }; + /** \brief Default constructor of the local storage. */ + LocalStorage(); + /** \brief Default deconstructor of the local storage. */ + ~LocalStorage(); + }; - /** \brief The LocalStorageHandler holds all (three) LocalStorages for the three 2D render windows. */ - mitk::LocalStorageHandler m_LSH; + /** \brief The LocalStorageHandler holds all (three) LocalStorages for the three 2D render windows. */ + mitk::LocalStorageHandler m_LSH; - protected: - /** +protected: + /** * @brief SurfaceVtkMapper2D default constructor. */ - SurfaceVtkMapper2D(); + SurfaceVtkMapper2D(); - /** + /** * @brief ~SurfaceVtkMapper2D default destructor. */ - virtual ~SurfaceVtkMapper2D(); + virtual ~SurfaceVtkMapper2D(); - /** + /** * @brief GenerateDataForRenderer produces all the data. * @param renderer The respective renderer of the mitkRenderWindow. */ - virtual void GenerateDataForRenderer(mitk::BaseRenderer* renderer); + virtual void GenerateDataForRenderer(mitk::BaseRenderer* renderer); - /** + /** * @brief ResetMapper Called in mitk::Mapper::Update to hide objects. * If TimeSlicedGeometry or time step is not valid, reset the mapper. * so that nothing is displayed e.g. toggle visiblity of the propassembly. * * @param renderer The respective renderer of the mitkRenderWindow. */ - virtual void ResetMapper( BaseRenderer* renderer ); + virtual void ResetMapper( BaseRenderer* renderer ); - /** + /** * @brief ApplyAllProperties Pass all the properties to VTK. * @param renderer The respective renderer of the mitkRenderWindow. */ - void ApplyAllProperties( BaseRenderer* renderer); + void ApplyAllProperties( BaseRenderer* renderer); - /** + /** * @brief Update Check if data should be generated. * @param renderer The respective renderer of the mitkRenderWindow. */ - void Update(BaseRenderer* renderer); + void Update(BaseRenderer* renderer); - int m_LineWidth; + int m_LineWidth; - bool m_DrawNormals; + bool m_DrawNormals; - float m_FrontSideColor[4]; - float m_BackSideColor[4]; - float m_LineColor[4]; - float m_FrontNormalLengthInPixels; - float m_BackNormalLengthInPixels; - }; + float m_FrontSideColor[4]; + float m_BackSideColor[4]; + float m_LineColor[4]; + float m_FrontNormalLengthInPixels; + float m_BackNormalLengthInPixels; +}; } // namespace mitk #endif /* mitkSurfaceVtkMapper2D_h */