vtkRenderUpdaterTimer.hpp
Go to the documentation of this file.
1 #ifndef RAM_PATH_PLANNING_VTK_RENDER_UPDATER_TIMER_HPP
2 #define RAM_PATH_PLANNING_VTK_RENDER_UPDATER_TIMER_HPP
3 
4 #include <vtkCommand.h>
5 #include <vtkInteractorStyleTrackballCamera.h>
6 #include <vtkPolyDataMapper.h>
7 #include <vtkProperty.h>
8 #include <vtkRenderWindow.h>
9 #include <vtkRenderWindowInteractor.h>
10 #include <vtkRenderer.h>
11 #include <vtkRendererCollection.h>
12 #include <vtkTransform.h>
13 #include <vtkTransformFilter.h>
14 
17 
18 typedef vtkSmartPointer<vtkPolyData> Polygon;
19 typedef std::vector<Polygon> PolygonVector;
20 typedef std::vector<PolygonVector> Layer;
21 
22 class vtkRendererUpdaterTimer : public vtkCommand
23 {
24 public:
26  {
28  return cb;
29  }
30 
31  vtkSmartPointer<vtkPolyData> mesh_ = vtkSmartPointer<vtkPolyData>::New();
32  vtkSmartPointer<vtkStripper> stripper_;
34 
35  virtual void Execute(vtkObject *caller,
36  unsigned long,
37  void * vtkNotUsed(callData))
38  {
39  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::SafeDownCast(caller);
40  vtkRenderer * renderer = iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer();
41 
42  int representation(1);
43  vtkActor* last_actor(renderer->GetActors()->GetLastActor());
44 
45  if (last_actor)
46  representation = last_actor->GetProperty()->GetRepresentation();
47 
48  renderer->RemoveAllViewProps(); // Remove all actors
49 
50  // Add mesh
51  if (mesh_)
52  {
53  vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
54  mapper->SetInputData(mesh_);
55 
56  vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
57  actor->SetMapper(mapper);
58 
59  actor->GetProperty()->SetColor(0.5, 0.5, 0.5);
60  actor->GetProperty()->SetOpacity(0.5);
61  actor->GetProperty()->SetRepresentation(representation);
62  renderer->AddActor(actor);
63  }
64 
65  if (stripper_)
66  {
67  vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
68  mapper->SetInputConnection(stripper_->GetOutputPort());
69  mapper->ScalarVisibilityOff();
70 
71  vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
72  actor->SetMapper(mapper);
73 
74  actor->GetProperty()->SetColor(1, 0, 0);
75  actor->GetProperty()->SetLineWidth(2.0);
76  actor->GetProperty()->SetRepresentation(representation);
77  renderer->AddActor(actor);
78  }
79 
80  // Add all polygons
81  for (unsigned i = 0; i < current_layer_.size(); ++i)
82  {
83  unsigned color_index(0);
84  for (auto polygon : current_layer_[i])
85  {
86  vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
87  mapper->SetInputData(polygon);
88 
89  vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
90  actor->SetMapper(mapper);
91  double rgb[3];
92  getColorFromIndex(color_index++, rgb);
93 
94  actor->GetProperty()->SetColor(rgb);
95  actor->GetProperty()->SetRepresentation(representation);
96  renderer->AddActor(actor);
97  }
98  }
99  iren->GetRenderWindow()->Render();
100  }
101 
102 private:
103  void getColorFromIndex(const unsigned i,
104  double rgb[3])
105  {
106  switch (i % 6)
107  {
108  case 0:
109  rgb[0] = 0.3;
110  rgb[1] = 0.3;
111  rgb[2] = 1;
112  break;
113  case 1:
114  rgb[0] = 0.3;
115  rgb[1] = 1;
116  rgb[2] = 0.3;
117  break;
118  case 2:
119  rgb[0] = 0.3;
120  rgb[1] = 1;
121  rgb[2] = 1;
122  break;
123  case 3:
124  rgb[0] = 1;
125  rgb[1] = 0.3;
126  rgb[2] = 0.3;
127  break;
128  case 4:
129  rgb[0] = 1;
130  rgb[1] = 0.3;
131  rgb[2] = 1;
132  break;
133  case 5:
134  rgb[0] = 1;
135  rgb[1] = 1;
136  rgb[2] = 0.3;
137  break;
138  default:
139  rgb[0] = 1;
140  rgb[1] = 1;
141  rgb[2] = 1;
142  break;
143  }
144  }
145 };
146 
147 #endif
std::vector< Polygon > PolygonVector
std::vector< PolygonVector > Layer
virtual void Execute(vtkObject *caller, unsigned long, void *vtkNotUsed(callData))
static vtkRendererUpdaterTimer * New()
void getColorFromIndex(const unsigned i, double rgb[3])
vtkSmartPointer< vtkPolyData > Polygon
vtkSmartPointer< vtkRendererUpdaterTimer > cb
vtkSmartPointer< vtkStripper > stripper_
vtkSmartPointer< vtkPolyData > mesh_


ram_path_planning
Author(s): Andres Campos - Institut Maupertuis
autogenerated on Mon Jun 10 2019 14:50:03