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 "mitkContourVtkMapper3D.h"
00020 #include "mitkDataNode.h"
00021 #include "mitkProperties.h"
00022 #include "mitkColorProperty.h"
00023 #include "mitkVtkPropRenderer.h"
00024 #include "mitkContour.h"
00025
00026 #include <vtkActor.h>
00027 #include <vtkAppendPolyData.h>
00028 #include <vtkAssembly.h>
00029 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
00030 #include <vtkCellArray.h>
00031 #pragma GCC diagnostic warning "-Wstrict-aliasing"
00032 #include <vtkFollower.h>
00033 #include <vtkLinearTransform.h>
00034 #include <vtkPolyData.h>
00035 #include <vtkPolyDataMapper.h>
00036 #include <vtkPolygon.h>
00037 #include <vtkProp3DCollection.h>
00038 #include <vtkProperty.h>
00039 #include <vtkRenderer.h>
00040 #include <vtkSphereSource.h>
00041 #include <vtkTubeFilter.h>
00042
00043 mitk::ContourVtkMapper3D::ContourVtkMapper3D()
00044 {
00045 m_VtkPolyDataMapper = vtkPolyDataMapper::New();
00046 m_VtkPointList = vtkAppendPolyData::New();
00047 m_Actor = vtkActor::New();
00048 m_Actor->SetMapper(m_VtkPolyDataMapper);
00049
00050 m_TubeFilter = vtkTubeFilter::New();
00051 }
00052
00053 mitk::ContourVtkMapper3D::~ContourVtkMapper3D()
00054 {
00055 if(m_VtkPolyDataMapper)
00056 m_VtkPolyDataMapper->Delete();
00057
00058 if(m_TubeFilter)
00059 m_TubeFilter->Delete();
00060
00061 if(m_VtkPointList)
00062 m_VtkPointList->Delete();
00063
00064 if(m_Contour)
00065 m_Contour->Delete();
00066
00067 if(m_Actor)
00068 m_Actor->Delete();
00069 }
00070
00071 vtkProp* mitk::ContourVtkMapper3D::GetVtkProp(mitk::BaseRenderer* )
00072 {
00073 return m_Actor;
00074 }
00075
00076 void mitk::ContourVtkMapper3D::GenerateData(mitk::BaseRenderer* renderer)
00077 {
00078 if ( IsVisible(renderer)==false )
00079 {
00080 m_Actor->VisibilityOff();
00081 return;
00082 }
00083 m_Actor->VisibilityOn();
00084
00085 m_Contour = vtkPolyData::New();
00086
00087 mitk::Contour::Pointer input = const_cast<mitk::Contour*>(this->GetInput());
00088 bool makeContour = true;
00089
00090 if ( makeContour )
00091 {
00092 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
00093 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
00094
00095 int numPts=input->GetNumberOfPoints();
00096 if ( numPts > 200000 )
00097 numPts = 200000;
00098 mitk::Contour::PathPointer path = input->GetContourPath();
00099 mitk::Contour::PathType::InputType cstart = path->StartOfInput();
00100 mitk::Contour::PathType::InputType cend = path->EndOfInput();
00101 mitk::Contour::PathType::InputType cstep = (cend-cstart+1)/numPts;
00102 mitk::Contour::PathType::InputType ccur;
00103
00104 vtkIdType ptIndex = 0;
00105 vtkIdType lastPointIndex = 0;
00106
00107 mitk::Contour::PointsContainerPointer contourPoints = input->GetPoints();
00108 mitk::Contour::PointsContainerIterator pointsIt = contourPoints->Begin();
00109
00110 vtkFloatingPointType vtkpoint[3];
00111
00112 int i;
00113 float pointSize = 2;
00114 this->GetDataNode()->GetFloatProperty("spheres size", pointSize);
00115
00116 bool showPoints = true;
00117 this->GetDataNode()->GetBoolProperty("show points", showPoints);
00118 if ( showPoints )
00119 {
00120 m_VtkPointList = vtkAppendPolyData::New();
00121 }
00122 for ( i=0, ccur=cstart; i<numPts; ++i, ccur+=cstep )
00123 {
00124 itk2vtk(path->Evaluate(ccur), vtkpoint);
00125 points->InsertPoint(ptIndex, vtkpoint);
00126 if ( ptIndex > 0 )
00127 {
00128 int cell[2] = {ptIndex-1,ptIndex};
00129 lines->InsertNextCell((vtkIdType)2,(vtkIdType*) cell);
00130 }
00131 lastPointIndex = ptIndex;
00132 ++ptIndex;
00133
00134 if ( showPoints )
00135 {
00136 vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
00137
00138 sphere->SetRadius(pointSize);
00139 sphere->SetCenter(vtkpoint);
00140
00141 m_VtkPointList->AddInput(sphere->GetOutput());
00142 sphere->Update();
00143 }
00144 }
00145
00146 if ( input->GetClosed() )
00147 {
00148 int cell[2] = {lastPointIndex,0};
00149 lines->InsertNextCell((vtkIdType)2,(vtkIdType*) cell);
00150 }
00151
00152 m_Contour->SetPoints(points);
00153 m_Contour->SetLines(lines);
00154 m_Contour->Update();
00155
00156 m_TubeFilter->SetInput(m_Contour);
00157 m_TubeFilter->SetRadius(pointSize / 2.0f);
00158 m_TubeFilter->SetNumberOfSides(8);
00159 m_TubeFilter->Update();
00160
00161 if ( showPoints )
00162 {
00163 m_VtkPointList->AddInput(m_TubeFilter->GetOutput());
00164 m_VtkPolyDataMapper->SetInput(m_VtkPointList->GetOutput());
00165 }
00166 else
00167 {
00168 m_VtkPolyDataMapper->SetInput(m_TubeFilter->GetOutput());
00169 }
00170 vtkFloatingPointType rgba[4]={0.0f,1.0f,0.0f,0.6f};
00171 m_Actor->GetProperty()->SetColor(rgba);
00172 m_Actor->SetMapper(m_VtkPolyDataMapper);
00173 }
00174
00175 SetVtkMapperImmediateModeRendering(m_VtkPolyDataMapper);
00176 }
00177
00178 const mitk::Contour* mitk::ContourVtkMapper3D::GetInput()
00179 {
00180 return static_cast<const mitk::Contour* > ( GetData() );
00181 }