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 "mitkLineVtkMapper3D.h"
00020
00021 #include <vtkPolyDataMapper.h>
00022 #include <vtkActor.h>
00023 #include <vtkProp3DCollection.h>
00024 #include <mitkProperties.h>
00025 #include "mitkStringProperty.h"
00026 #include <vtkProperty.h>
00027
00028 mitk::LineVtkMapper3D::LineVtkMapper3D()
00029 : PointSetVtkMapper3D()
00030 {
00031 }
00032
00033 mitk::LineVtkMapper3D::~LineVtkMapper3D()
00034 {
00035 }
00036
00037 void mitk::LineVtkMapper3D::GenerateData(mitk::BaseRenderer* renderer)
00038 {
00039 if(IsVisible(renderer)==false)
00040 {
00041 m_Actor->VisibilityOff();
00042 return;
00043 }
00044
00045 m_Actor->VisibilityOn();
00046
00047 m_vtkPointList->Delete();
00048 m_vtkTextList->Delete();
00049 m_contour->Delete();
00050 m_tubefilter->Delete();
00051
00052 m_vtkPointList = vtkAppendPolyData::New();
00053 m_vtkTextList = vtkAppendPolyData::New();
00054 m_contour = vtkPolyData::New();
00055 m_tubefilter = vtkTubeFilter::New();
00056
00057
00058 mitk::PointSet::Pointer input = const_cast<mitk::PointSet*>(this->GetInput());
00059 mitk::PointSet::PointSetType::Pointer pointList;
00060
00061 pointList = input->GetPointList();
00062
00063 mitk::PointSet::PointsContainer::Iterator i;
00064
00065 int j;
00066 bool makeContour;
00067 if (dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("show contour").GetPointer()) == NULL)
00068 makeContour = false;
00069 else
00070 makeContour = dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("show contour").GetPointer())->GetValue();
00071
00072 vtkPoints *points = vtkPoints::New();
00073 vtkCellArray *polys = vtkCellArray::New();
00074
00075 for (j=0, i=pointList->GetPoints()->Begin(); i!=pointList->GetPoints()->End() ; i++,j++)
00076 {
00077 int cell[2] = {j-1,j};
00078 points->InsertPoint(j,i.Value()[0],i.Value()[1],i.Value()[2]);
00079 if (j>0)
00080 polys->InsertNextCell(2,cell);
00081 }
00082
00083 bool close;
00084 if (dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("close contour").GetPointer()) == NULL)
00085 close = false;
00086 else
00087 close = dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("close contour").GetPointer())->GetValue();
00088
00089 if (close)
00090 {
00091 int cell[2] = {j-1,0};
00092 polys->InsertNextCell(2,cell);
00093 }
00094
00095 m_contour->SetPoints(points);
00096 points->Delete();
00097 m_contour->SetLines(polys);
00098 polys->Delete();
00099 m_contour->Update();
00100
00101 m_tubefilter->SetInput(m_contour);
00102 m_tubefilter->SetRadius(1);
00103 m_tubefilter->Update();;
00104
00105 m_vtkPointList->AddInput(m_tubefilter->GetOutput());
00106
00107
00108
00109 float rgba[4]={1.0f,1.0f,1.0f,1.0f};
00110 GetColor(rgba, renderer);
00111
00112 for (j=0, i=pointList->GetPoints()->Begin(); i!=pointList->GetPoints()->End() ; i++,j++)
00113 {
00114 vtkSphereSource *sphere = vtkSphereSource::New();
00115
00116 sphere->SetRadius(2);
00117 sphere->SetCenter(i.Value()[0],i.Value()[1],i.Value()[2]);
00118
00119 m_vtkPointList->AddInput(sphere->GetOutput());
00120
00121 if (dynamic_cast<mitk::StringProperty *>(this->GetDataNode()->GetProperty("label").GetPointer()) == NULL)
00122 {
00123 }
00124 else
00125 {
00126 const char * pointLabel =dynamic_cast<mitk::StringProperty *>(this->GetDataNode()->GetProperty("label").GetPointer())->GetValue();
00127 char buffer[20];
00128 std::string l = pointLabel;
00129 if (input->GetSize()>1)
00130 {
00131 sprintf(buffer,"%d",j+1);
00132 l.append(buffer);
00133 }
00134
00135
00136 vtkVectorText *label = vtkVectorText::New();
00137 label->SetText(l.c_str());
00138
00139
00140 vtkTransform *aLabelTransform =vtkTransform::New();
00141 aLabelTransform->Identity();
00142 aLabelTransform->Translate(i.Value()[0]+2,i.Value()[1]+2,i.Value()[2]);
00143 aLabelTransform->Scale(5.7,5.7,5.7);
00144
00145
00146 vtkTransformPolyDataFilter *labelTransform = vtkTransformPolyDataFilter::New();
00147 labelTransform->SetTransform(aLabelTransform);
00148 labelTransform->SetInput(label->GetOutput());
00149
00150 m_vtkPointList->AddInput(labelTransform->GetOutput());
00151 }
00152
00153
00154 }
00155
00156
00157 m_VtkPolyDataMapper->SetInput(m_vtkPointList->GetOutput());
00158 m_Actor->GetProperty()->SetColor(rgba);
00159 }
00160