Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkContourSetVtkMapper3D.h"
00020 #include "mitkDataNode.h"
00021 #include "mitkProperties.h"
00022 #include "mitkColorProperty.h"
00023 #include "mitkVtkPropRenderer.h"
00024
00025
00026 #include <vtkActor.h>
00027 #include <vtkActor.h>
00028 #include <vtkCellArray.h>
00029 #include <vtkAppendPolyData.h>
00030 #include <vtkPolyData.h>
00031 #include <vtkPolyDataMapper.h>
00032 #include <vtkFollower.h>
00033 #include <vtkAssembly.h>
00034 #include <vtkProp3DCollection.h>
00035 #include <vtkRenderer.h>
00036 #include <vtkLinearTransform.h>
00037 #include <vtkTubeFilter.h>
00038 #include <vtkPolygon.h>
00039
00040
00041 #include <vtkProperty.h>
00042 #include <vtkPolyDataMapper.h>
00043 #include <stdlib.h>
00044
00045
00046 mitk::ContourSetVtkMapper3D::ContourSetVtkMapper3D()
00047 {
00048 m_VtkPolyDataMapper = vtkPolyDataMapper::New();
00049 m_Actor = vtkActor::New();
00050 m_Actor->SetMapper(m_VtkPolyDataMapper);
00051
00052 m_ContourSet = vtkPolyData::New();
00053 m_TubeFilter = vtkTubeFilter::New();
00054 }
00055
00056 mitk::ContourSetVtkMapper3D::~ContourSetVtkMapper3D()
00057 {
00058 if( m_VtkPolyDataMapper )
00059 m_VtkPolyDataMapper->Delete();;
00060
00061 if( m_TubeFilter )
00062 m_TubeFilter->Delete();;
00063
00064 if( m_ContourSet )
00065 m_ContourSet->Delete();;
00066
00067 if( m_Actor )
00068 m_Actor->Delete();;
00069 }
00070
00071 vtkProp* mitk::ContourSetVtkMapper3D::GetVtkProp(mitk::BaseRenderer* )
00072 {
00073 return m_Actor;
00074 }
00075
00076 void mitk::ContourSetVtkMapper3D::GenerateData(mitk::BaseRenderer* renderer)
00077 {
00078 if(IsVisible(renderer)==false)
00079 {
00080 m_Actor->VisibilityOff();
00081 return;
00082 }
00083 m_Actor->VisibilityOn();
00084
00085 mitk::ContourSet::Pointer input = const_cast<mitk::ContourSet*>(this->GetInput());
00086
00087 if ( renderer->GetDisplayGeometryUpdateTime() > this->GetInput()->GetMTime() )
00088 {
00089 m_ContourSet = vtkPolyData::New();
00090
00091 vtkPoints *points = vtkPoints::New();
00092 vtkCellArray *lines = vtkCellArray::New();
00093
00094 mitk::ContourSet::Pointer input = const_cast<mitk::ContourSet*>(this->GetInput());
00095 mitk::ContourSet::ContourVectorType contourVec = input->GetContours();
00096 mitk::ContourSet::ContourIterator contourIt = contourVec.begin();
00097
00098 vtkIdType firstPointIndex= 0, lastPointIndex=0;
00099
00100 vtkIdType ptIndex = 0;
00101 while ( contourIt != contourVec.end() )
00102 {
00103 mitk::Contour* nextContour = (mitk::Contour*) (*contourIt).second;
00104 Contour::InputType idx = nextContour->GetContourPath()->StartOfInput();
00105
00106
00107 Contour::InputType end = nextContour->GetContourPath()->EndOfInput();
00108 if (end > 50000) end = 0;
00109
00110 mitk::Contour::PointsContainerPointer contourPoints = nextContour->GetPoints();
00111 mitk::Contour::PointsContainerIterator pointsIt = contourPoints->Begin();
00112 unsigned int counter = 0;
00113
00114 firstPointIndex=ptIndex;
00115 while ( pointsIt != contourPoints->End() )
00116 {
00117 if (counter %2 == 0)
00118 {
00119 Contour::BoundingBoxType::PointType point;
00120 point = pointsIt.Value();
00121 points->InsertPoint(ptIndex, point[0],point[1],point[2]);
00122 if (ptIndex > firstPointIndex)
00123 {
00124 int cell[2] = {ptIndex-1,ptIndex};
00125 lines->InsertNextCell((vtkIdType)2,(vtkIdType*) cell);
00126 }
00127 lastPointIndex=ptIndex;
00128 ptIndex++;
00129 }
00130 pointsIt++;
00131 idx+=1;
00132 }
00133
00134 if (nextContour->GetClosed())
00135 {
00136 int cell[2] = {lastPointIndex,firstPointIndex};
00137 lines->InsertNextCell((vtkIdType)2,(vtkIdType*) cell);
00138 }
00139 contourIt++;
00140 }
00141
00142 m_ContourSet->SetPoints(points);
00143 m_ContourSet->SetLines(lines);
00144 m_ContourSet->Update();
00145
00146 m_TubeFilter->SetInput(m_ContourSet);
00147 m_TubeFilter->SetRadius(1);
00148 m_TubeFilter->Update();
00149 m_VtkPolyDataMapper->SetInput(m_TubeFilter->GetOutput());
00150
00151 vtkFloatingPointType rgba[4]={0.0f,1.0f,0.0f,0.6f};
00152
00153 m_Actor->GetProperty()->SetColor(rgba);
00154 m_Actor->SetMapper(m_VtkPolyDataMapper);
00155 }
00156
00157 SetVtkMapperImmediateModeRendering(m_VtkPolyDataMapper);
00158 }
00159
00160 const mitk::ContourSet* mitk::ContourSetVtkMapper3D::GetInput()
00161 {
00162 return static_cast<const mitk::ContourSet* > ( GetData() );
00163 }