9 #include "vtkAssemblyPath.h" 10 #include "vtkCellPicker.h" 11 #include "vtkCamera.h" 12 #include "vtkCleanPolyData.h" 13 #include "vtkCoordinate.h" 14 #include "vtkCylinderSource.h" 15 #include "vtkFollower.h" 16 #include "vtkInteractorObserver.h" 19 #include "vtkObjectFactory.h" 20 #include "vtkPolyDataMapper.h" 21 #include "vtkPolyDataNormals.h" 22 #include "vtkProperty.h" 23 #include "vtkRenderer.h" 24 #include "vtkRenderWindow.h" 27 #include "fwRenderVTK/vtk/MarkedSphereHandleRepresentation.hpp" 35 vtkStandardNewMacro(MarkedSphereHandleRepresentation);
38 MarkedSphereHandleRepresentation::MarkedSphereHandleRepresentation() : vtkSphereHandleRepresentation()
40 this->Marker = vtkCylinderSource::New();
41 this->Marker->SetCenter(0.,-1.,0.);
42 this->Marker->SetResolution(64);
43 this->Marker->SetHeight(0.);
45 this->CleanPolyData = vtkCleanPolyData::New();
46 this->CleanPolyData->PointMergingOn();
47 this->CleanPolyData->CreateDefaultLocator();
48 this->CleanPolyData->SetInputConnection(0, this->Marker->GetOutputPort(0));
50 vtkPolyDataNormals *MarkerNormals = vtkPolyDataNormals::New();
51 MarkerNormals->SetInputConnection( 0, this->CleanPolyData->GetOutputPort(0) );
53 this->MarkerMapper = vtkPolyDataMapper::New();
54 this->MarkerMapper->SetInputConnection( MarkerNormals->GetOutputPort() );
55 MarkerNormals->Delete();
57 this->Follower = vtkFollower::New();
58 this->Follower->SetMapper(this->MarkerMapper);
59 this->Follower->RotateX(90);
62 this->CreateDefaultProperties();
64 this->MarkerRadiusFactor = 1.5;
65 this->SetMarkerProperty(this->MarkerProperty);
66 this->Marker->SetRadius(this->MarkerRadiusFactor * this->Sphere->GetRadius());
70 MarkedSphereHandleRepresentation::~MarkedSphereHandleRepresentation()
72 this->Marker->Delete();
73 this->CleanPolyData->Delete();
74 this->MarkerMapper->Delete();
75 this->Follower->Delete();
76 this->MarkerProperty->Delete();
80 void MarkedSphereHandleRepresentation::SetWorldPosition(
double p[3])
82 this->vtkSphereHandleRepresentation::SetWorldPosition(p);
83 this->Follower->SetPosition(this->GetWorldPosition());
87 void MarkedSphereHandleRepresentation::CreateDefaultProperties()
89 this->MarkerProperty = vtkProperty::New();
90 this->MarkerProperty->SetColor(1., 1., 0.);
91 this->MarkerProperty->SetOpacity(0.5);
95 void MarkedSphereHandleRepresentation::BuildRepresentation()
109 this->Sphere->Update();
111 this->Follower->SetCamera( this->GetRenderer()->GetActiveCamera() );
112 this->Marker->SetRadius(this->MarkerRadiusFactor * this->Sphere->GetRadius() );
113 this->Marker->Update();
114 this->BuildTime.Modified();
120 void MarkedSphereHandleRepresentation::GetActors(vtkPropCollection *pc)
122 this->Actor->GetActors(pc);
123 this->Follower->GetActors(pc);
127 void MarkedSphereHandleRepresentation::ReleaseGraphicsResources(vtkWindow *win)
129 this->Actor->ReleaseGraphicsResources(win);
130 this->Follower->ReleaseGraphicsResources(win);
134 int MarkedSphereHandleRepresentation::RenderOpaqueGeometry(vtkViewport *viewport)
136 this->BuildRepresentation();
138 if (this->GetRenderer()->GetActiveCamera()->GetParallelProjection())
140 ret = this->Follower->RenderOpaqueGeometry(viewport);
142 return this->Actor->RenderOpaqueGeometry(viewport) + ret;
146 int MarkedSphereHandleRepresentation::RenderTranslucentPolygonalGeometry(vtkViewport *viewport)
148 this->BuildRepresentation();
150 if (this->GetRenderer()->GetActiveCamera()->GetParallelProjection())
152 ret = this->Follower->RenderTranslucentPolygonalGeometry(viewport);
154 return this->Actor->RenderTranslucentPolygonalGeometry(viewport) + ret;
158 int MarkedSphereHandleRepresentation::HasTranslucentPolygonalGeometry()
164 void MarkedSphereHandleRepresentation::SetMarkerProperty(vtkProperty * p)
166 vtkSetObjectBodyMacro(MarkerProperty, vtkProperty, p);
169 this->Follower->SetProperty( p );
174 void MarkedSphereHandleRepresentation::PrintSelf(ostream& os, vtkIndent indent)
176 this->vtkSphereHandleRepresentation::PrintSelf(os,indent);
178 if ( this->MarkerProperty )
180 os << indent <<
"Selected Property: " << this->MarkerProperty <<
"\n";
184 os << indent <<
"Marker Property: (none)\n";
187 this->Sphere->PrintSelf(os,indent.GetNextIndent());
The namespace fwRenderVTK contains classes for rendering with VTK.