diff --git a/Modules/ContourModel/Rendering/mitkContourModelSetMapper3D.cpp b/Modules/ContourModel/Rendering/mitkContourModelSetMapper3D.cpp index 5c2a4dc5df..0445c2a84f 100644 --- a/Modules/ContourModel/Rendering/mitkContourModelSetMapper3D.cpp +++ b/Modules/ContourModel/Rendering/mitkContourModelSetMapper3D.cpp @@ -1,206 +1,242 @@ /*=================================================================== 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 #include #include +#include #include #include "mitkSurface.h" mitk::ContourModelSetMapper3D::ContourModelSetMapper3D() { } mitk::ContourModelSetMapper3D::~ContourModelSetMapper3D() { } const mitk::ContourModelSet* mitk::ContourModelSetMapper3D::GetInput( void ) { //convient way to get the data from the dataNode return static_cast< const mitk::ContourModelSet * >( GetDataNode()->GetData() ); } vtkProp* mitk::ContourModelSetMapper3D::GetVtkProp(mitk::BaseRenderer* renderer) { //return the actor corresponding to the renderer return m_LSH.GetLocalStorage(renderer)->m_Assembly; } void mitk::ContourModelSetMapper3D::GenerateDataForRenderer( mitk::BaseRenderer *renderer ) { /* First convert the contourModel to vtkPolyData, then tube filter it and * set it input for our mapper */ LocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); - mitk::ContourModelSet* contourSet = static_cast< mitk::ContourModelSet* >( GetDataNode()->GetData() ); + ContourModelSet* contourModelSet = dynamic_cast(this->GetDataNode()->GetData()); - mitk::ContourModelSet::ContourModelSetIterator it = contourSet->Begin(); - mitk::ContourModelSet::ContourModelSetIterator end = contourSet->End(); - - while(it!=end) + if (contourModelSet != NULL) { - mitk::ContourModel* inputContour = it->GetPointer(); - vtkSmartPointer polyData = this->CreateVtkPolyDataFromContour(inputContour, renderer); + vtkSmartPointer points = vtkSmartPointer::New(); + vtkSmartPointer cells = vtkSmartPointer::New(); + vtkIdType baseIndex = 0; - vtkSmartPointer tubeFilter = vtkSmartPointer::New(); - tubeFilter->SetInputData(polyData); + ContourModelSet::ContourModelSetIterator it = contourModelSet->Begin(); + ContourModelSet::ContourModelSetIterator end = contourModelSet->End(); - float lineWidth(1.0); - if (this->GetDataNode()->GetFloatProperty( "contour.3D.width", lineWidth, renderer )) - { - tubeFilter->SetRadius(lineWidth); - }else - { - tubeFilter->SetRadius(0.5); - } - tubeFilter->CappingOn(); - tubeFilter->SetNumberOfSides(10); - tubeFilter->Update(); + while (it != end) + { + ContourModel* contourModel = it->GetPointer(); - vtkSmartPointer mapper = vtkSmartPointer::New(); - vtkSmartPointer actor = vtkSmartPointer::New(); - actor->SetMapper(mapper); + ContourModel::VertexIterator vertIt = contourModel->Begin(); + ContourModel::VertexIterator vertEnd = contourModel->End(); - mapper->SetInputConnection(tubeFilter->GetOutputPort()); - //mapper->SetInput(polyData); + while (vertIt != vertEnd) + { + points->InsertNextPoint((*vertIt)->Coordinates[0], (*vertIt)->Coordinates[1], (*vertIt)->Coordinates[2]); + ++vertIt; + } - localStorage->m_Assembly->AddPart(actor); + vtkSmartPointer line = vtkSmartPointer::New(); + vtkIdList* pointIds = line->GetPointIds(); - ++it; - } + vtkIdType numPoints = contourModel->GetNumberOfVertices(); + pointIds->SetNumberOfIds(numPoints + 1); + for (vtkIdType i = 0; i < numPoints; ++i) + pointIds->SetId(i, baseIndex + i); - this->ApplyContourProperties(renderer); + pointIds->SetId(numPoints, baseIndex); + + cells->InsertNextCell(line); + baseIndex += numPoints; + + + ++it; + } + + vtkSmartPointer polyData = vtkSmartPointer::New(); + polyData->SetPoints(points); + polyData->SetLines(cells); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + mapper->SetInputData(polyData); + + localStorage->m_Assembly->AddPart(actor); + } + this->ApplyContourProperties(renderer); + this->ApplyContourModelSetProperties(renderer); } void mitk::ContourModelSetMapper3D::Update(mitk::BaseRenderer* renderer) { bool visible = true; GetDataNode()->GetVisibility(visible, renderer, "visible"); mitk::ContourModel* data = static_cast< mitk::ContourModel*>( GetDataNode()->GetData() ); if ( data == NULL ) { return; } // Calculate time step of the input data for the specified renderer (integer value) this->CalculateTimeStep( renderer ); LocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); if ( this->GetTimestep() == -1 ) { return; } const DataNode *node = this->GetDataNode(); data->UpdateOutputInformation(); //check if something important has changed and we need to rerender if ( (localStorage->m_LastUpdateTime < node->GetMTime()) //was the node modified? || (localStorage->m_LastUpdateTime < data->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(); } vtkSmartPointer mitk::ContourModelSetMapper3D::CreateVtkPolyDataFromContour(mitk::ContourModel* inputContour, mitk::BaseRenderer* renderer) { unsigned int timestep = this->GetTimestep(); LocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); localStorage->m_contourToPolyData->SetInput(inputContour); localStorage->m_contourToPolyData->Update(); vtkSmartPointer polyData = vtkSmartPointer::New(); polyData = localStorage->m_contourToPolyData->GetOutput()->GetVtkPolyData(timestep); return polyData; } +void mitk::ContourModelSetMapper3D::ApplyContourModelSetProperties(BaseRenderer* renderer) +{ + LocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); + DataNode* dataNode = this->GetDataNode(); + if (dataNode != NULL) + { + float lineWidth = 1; + dataNode->GetFloatProperty("contour.3D.width", lineWidth, renderer); + + vtkSmartPointer collection = vtkSmartPointer::New(); + localStorage->m_Assembly->GetActors(collection); + collection->InitTraversal(); + for(vtkIdType i = 0; i < collection->GetNumberOfItems(); i++) + { + vtkActor::SafeDownCast(collection->GetNextProp())->GetProperty()->SetLineWidth(lineWidth); + } + } +} void mitk::ContourModelSetMapper3D::ApplyContourProperties(mitk::BaseRenderer* renderer) { LocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); mitk::ColorProperty::Pointer colorprop = dynamic_cast(GetDataNode()->GetProperty ("contour.color", renderer)); if(colorprop) { //set the color of the contour double red = colorprop->GetColor().GetRed(); double green = colorprop->GetColor().GetGreen(); double blue = colorprop->GetColor().GetBlue(); vtkSmartPointer collection = vtkSmartPointer::New(); localStorage->m_Assembly->GetActors(collection); collection->InitTraversal(); for(vtkIdType i = 0; i < collection->GetNumberOfItems(); i++) { vtkActor::SafeDownCast(collection->GetNextProp())->GetProperty()->SetColor(red, green, blue); } } } /*+++++++++++++++++++ LocalStorage part +++++++++++++++++++++++++*/ mitk::ContourModelSetMapper3D::LocalStorage* mitk::ContourModelSetMapper3D::GetLocalStorage(mitk::BaseRenderer* renderer) { return m_LSH.GetLocalStorage(renderer); } mitk::ContourModelSetMapper3D::LocalStorage::LocalStorage() { m_Assembly = vtkSmartPointer::New(); m_contourToPolyData = mitk::ContourModelToSurfaceFilter::New(); } void mitk::ContourModelSetMapper3D::SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer, bool overwrite) { node->AddProperty( "color", ColorProperty::New(1.0,0.0,0.0), renderer, overwrite ); node->AddProperty( "contour.3D.width", mitk::FloatProperty::New( 0.5 ), renderer, overwrite ); Superclass::SetDefaultProperties(node, renderer, overwrite); } diff --git a/Modules/ContourModel/Rendering/mitkContourModelSetMapper3D.h b/Modules/ContourModel/Rendering/mitkContourModelSetMapper3D.h index c53d82d355..27125e6391 100644 --- a/Modules/ContourModel/Rendering/mitkContourModelSetMapper3D.h +++ b/Modules/ContourModel/Rendering/mitkContourModelSetMapper3D.h @@ -1,107 +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 _MITK_CONTOURMODELSET_MAPPER_3D_H_ #define _MITK_CONTOURMODELSET_MAPPER_3D_H_ #include "mitkCommon.h" #include #include "mitkBaseRenderer.h" #include "mitkVtkMapper.h" #include "mitkContourModel.h" #include "mitkContourModelSet.h" #include "mitkContourModelToSurfaceFilter.h" #include #include #include #include #include #include #include namespace mitk { class MITKCONTOURMODEL_EXPORT ContourModelSetMapper3D : public VtkMapper { public: /** Standard class typedefs. */ mitkClassMacro( ContourModelSetMapper3D,VtkMapper ); /** Method for creation through the object factory. */ itkFactorylessNewMacro(Self) itkCloneMacro(Self) const mitk::ContourModelSet* GetInput(void); /** \brief Checks whether this mapper needs to update itself and generate * data. */ virtual void Update(mitk::BaseRenderer * renderer) override; /*+++ methods of MITK-VTK rendering pipeline +++*/ virtual vtkProp* GetVtkProp(mitk::BaseRenderer* renderer) override; /*+++ END methods of MITK-VTK rendering pipeline +++*/ class MITKCONTOURMODEL_EXPORT LocalStorage : public mitk::Mapper::BaseLocalStorage { public: /** \brief Assembly of contours. */ vtkSmartPointer m_Assembly; mitk::ContourModelToSurfaceFilter::Pointer m_contourToPolyData; /** \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() { } }; /** \brief The LocalStorageHandler holds all (three) LocalStorages for the three 2D render windows. */ mitk::LocalStorageHandler m_LSH; /** \brief Get the LocalStorage corresponding to the current renderer. */ LocalStorage* GetLocalStorage(mitk::BaseRenderer* renderer); /** \brief Set the default properties for general image rendering. */ static void SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer = NULL, bool overwrite = false); protected: ContourModelSetMapper3D(); virtual ~ContourModelSetMapper3D(); void GenerateDataForRenderer( mitk::BaseRenderer *renderer ) override; virtual vtkSmartPointer CreateVtkPolyDataFromContour(mitk::ContourModel* inputContour,mitk::BaseRenderer* renderer); virtual void ApplyContourProperties(mitk::BaseRenderer* renderer); + virtual void ApplyContourModelSetProperties(BaseRenderer *renderer); }; } #endif