Point Cloud Library (PCL)  1.7.2
axes.h
1 #ifndef PCL_OUTOFCORE_AXES_H_
2 #define PCL_OUTOFCORE_AXES_H_
3 
4 // C++
5 #include <iostream>
6 #include <string>
7 
8 // PCL
9 #include "object.h"
10 
11 // VTK
12 #include <vtkVersion.h>
13 #include <vtkActor.h>
14 #include <vtkTubeFilter.h>
15 #include <vtkAxes.h>
16 //#include <vtkDataSetMapper.h>
17 #include <vtkFloatArray.h>
18 #include <vtkProperty.h>
19 #include <vtkPolyData.h>
20 #include <vtkPolyDataMapper.h>
21 #include <vtkSmartPointer.h>
22 
23 class Axes : public Object
24 {
25 public:
26 
27  // Operators
28  // -----------------------------------------------------------------------------
29  Axes (std::string name, float size = 1.0) :
30  Object (name)
31  {
32  axes_ = vtkSmartPointer<vtkAxes>::New ();
33  axes_->SetOrigin (0, 0, 0);
34  axes_->SetScaleFactor (size);
35  axes_->Update ();
36 
37  vtkSmartPointer<vtkFloatArray> axes_colors = vtkSmartPointer<vtkFloatArray>::New ();
38  axes_colors->Allocate (6);
39  axes_colors->InsertNextValue (0.0);
40  axes_colors->InsertNextValue (0.0);
41  axes_colors->InsertNextValue (0.5);
42  axes_colors->InsertNextValue (0.5);
43  axes_colors->InsertNextValue (1.0);
44  axes_colors->InsertNextValue (1.0);
45 
46  vtkSmartPointer<vtkPolyData> axes_data = axes_->GetOutput ();
47  axes_data->GetPointData ()->SetScalars (axes_colors);
48 
49  vtkSmartPointer<vtkTubeFilter> axes_tubes = vtkSmartPointer<vtkTubeFilter>::New ();
50 #if VTK_MAJOR_VERSION < 6
51  axes_tubes->SetInput (axes_data);
52 #else
53  axes_tubes->SetInputData (axes_data);
54 #endif
55  axes_tubes->SetRadius (axes_->GetScaleFactor () / 100.0);
56  axes_tubes->SetNumberOfSides (6);
57 
58  vtkSmartPointer<vtkPolyDataMapper> axes_mapper = vtkSmartPointer<vtkPolyDataMapper>::New ();
59  axes_mapper->SetScalarModeToUsePointData ();
60 #if VTK_MAJOR_VERSION < 6
61  axes_mapper->SetInput (axes_tubes->GetOutput ());
62 #else
63  axes_mapper->SetInputData (axes_tubes->GetOutput ());
64 #endif
65 
66  axes_actor_ = vtkSmartPointer<vtkActor>::New ();
67  axes_actor_->GetProperty ()->SetLighting (false);
68  axes_actor_->SetMapper (axes_mapper);
69 
70  addActor (axes_actor_);
71  }
72  //~Axes () { }
73 
74  // Accessors
75  // -----------------------------------------------------------------------------
76  inline vtkSmartPointer<vtkAxes>
77  getAxes () const
78  {
79  return axes_;
80  }
81 
82  vtkSmartPointer<vtkActor>
83  getAxesActor () const
84  {
85  return axes_actor_;
86  }
87 
88 private:
89 
90  // Members
91  // -----------------------------------------------------------------------------
92  vtkSmartPointer<vtkAxes> axes_;
93  vtkSmartPointer<vtkActor> axes_actor_;
94 
95 };
96 
97 #endif
98