LVRVtkArrow.cpp
Go to the documentation of this file.
1 
34 #include "LVRVtkArrow.hpp"
35 
36 #include "lvr2/geometry/Normal.hpp"
37 
38 #include <vtkArrowSource.h>
39 #include <vtkPolyData.h>
40 #include <vtkSmartPointer.h>
41 #include <vtkPolyDataMapper.h>
42 #include <vtkActor.h>
43 #include <vtkRenderWindow.h>
44 #include <vtkRenderer.h>
45 #include <vtkRenderWindowInteractor.h>
46 #include <vtkMath.h>
47 #include <vtkSphereSource.h>
48 #include <vtkCubeSource.h>
49 #include <vtkProperty.h>
50 #include <vtkTransform.h>
51 #include <vtkTransformPolyDataFilter.h>
52 
53 namespace lvr2
54 {
55 
57  m_start(start), m_end(end)
58 {
59  //Create an arrow.
60  vtkSmartPointer<vtkArrowSource> arrowSource = vtkSmartPointer<vtkArrowSource>::New();
61 
62  // The x-axis is a vector from start to end
63  Vec diff = end - start;
64  Normal<float> x_axis(diff);
65  double length = diff.length();
66 
67  // The Z axis is an arbitrary vecotr cross X
68  double arbitrary[3];
69  vtkMath::RandomSeed(8775070);
70  arbitrary[0] = vtkMath::Random(-10,10);
71  arbitrary[1] = vtkMath::Random(-10,10);
72  arbitrary[2] = vtkMath::Random(-10,10);
73  Vec dummy(arbitrary[0], arbitrary[1], arbitrary[2]);
74 
75  // Compute other two local base vectors
76  Normal<float> z_axis(x_axis.cross(dummy));
77  Normal<float> y_axis(z_axis.cross(x_axis));
78 
79  vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
80  matrix->Identity();
81  for (unsigned int i = 0; i < 3; i++)
82  {
83  matrix->SetElement(i, 0, x_axis[i]);
84  matrix->SetElement(i, 1, y_axis[i]);
85  matrix->SetElement(i, 2, z_axis[i]);
86  }
87 
88  // Apply the transforms
89  vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
90  transform->Translate(start[0], start[1], start[2]);
91  transform->Concatenate(matrix);
92  transform->Scale(length, length, length);
93 
94  // Transform the polydata
95  vtkSmartPointer<vtkTransformPolyDataFilter> transformPD = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
96  transformPD->SetTransform(transform);
97  transformPD->SetInputConnection(arrowSource->GetOutputPort());
98 
99  //Create a mapper and actor for the arrow
100  vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
101  m_arrowActor = vtkSmartPointer<vtkActor>::New();
102  mapper->SetInputConnection(arrowSource->GetOutputPort());
103  m_arrowActor->SetUserMatrix(transform->GetMatrix());
104  m_arrowActor->SetMapper(mapper);
105 
106  //Store default color and set new color to red (the new arrow is active)
107  m_arrowActor->GetProperty()->GetColor(m_r, m_g, m_b);
108  setTmpColor(1.0, 0.2, 0.2);
109 
110  //UNDO THIS
111  vtkSmartPointer<vtkCubeSource> cubeStartSource = vtkSmartPointer<vtkCubeSource>::New();
112  cubeStartSource->SetBounds(start[0], start[0] + 1, start[1], start[1] + 1,start[2], start[2] + 1);
113  vtkSmartPointer<vtkPolyDataMapper> cubeStartMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
114  cubeStartMapper->SetInputConnection(cubeStartSource->GetOutputPort());
115 
116  //UNDO THIS END
117 
118 
119  // Create spheres for start and end point
120  vtkSmartPointer<vtkSphereSource> sphereStartSource = vtkSmartPointer<vtkSphereSource>::New();
121  sphereStartSource->SetCenter(start[0], start[1], start[2]);
122  vtkSmartPointer<vtkPolyDataMapper> sphereStartMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
123  sphereStartMapper->SetInputConnection(sphereStartSource->GetOutputPort());
124  m_startActor = vtkSmartPointer<vtkActor>::New();
125  //UNDO THIS
126  //m_startActor->SetMapper(sphereStartMapper);
127  //UNDO THIS END
128  m_startActor->SetMapper(cubeStartMapper);
129  m_startActor->GetProperty()->SetColor(1.0, 1.0, .3);
130 
131  vtkSmartPointer<vtkSphereSource> sphereEndSource = vtkSmartPointer<vtkSphereSource>::New();
132  sphereEndSource->SetCenter(end[0], end[1], end[2]);
133  vtkSmartPointer<vtkPolyDataMapper> sphereEndMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
134  sphereEndMapper->SetInputConnection(sphereEndSource->GetOutputPort());
135  m_endActor = vtkSmartPointer<vtkActor>::New();
136  m_endActor->SetMapper(sphereEndMapper);
137  m_endActor->GetProperty()->SetColor(1.0, .3, .3);
138 }
139 
141 {
142  m_arrowActor->GetProperty()->SetColor(m_r, m_g, m_b);
143 }
144 
145 void LVRVtkArrow::setTmpColor(double r, double g, double b)
146 {
147  m_arrowActor->GetProperty()->SetColor(r, g, b);
148 }
149 
150 vtkSmartPointer<vtkActor> LVRVtkArrow::getArrowActor()
151 {
152  return m_arrowActor;
153 }
154 
155 vtkSmartPointer<vtkActor> LVRVtkArrow::getStartActor()
156 {
157  return m_startActor;
158 }
159 
160 vtkSmartPointer<vtkActor> LVRVtkArrow::getEndActor()
161 {
162  return m_endActor;
163 }
164 
166 {
167  // TODO Auto-generated destructor stub
168 }
169 
170 } /* namespace lvr2 */
lvr2::LVRVtkArrow::setTmpColor
void setTmpColor(double r, double g, double b)
Definition: LVRVtkArrow.cpp:145
lvr2::LVRVtkArrow::getEndActor
vtkSmartPointer< vtkActor > getEndActor()
Definition: LVRVtkArrow.cpp:160
lvr2::BaseVector::length
CoordT length() const
Returns the length of this vector.
lvr2::LVRVtkArrow::m_r
double m_r
Definition: LVRVtkArrow.hpp:72
lvr2::BaseVector< float >
transform
Definition: src/tools/lvr2_transform/Options.cpp:44
lvr2::LVRVtkArrow::LVRVtkArrow
LVRVtkArrow(Vec start, Vec end)
Definition: LVRVtkArrow.cpp:56
lvr2::LVRVtkArrow::getStartActor
vtkSmartPointer< vtkActor > getStartActor()
Definition: LVRVtkArrow.cpp:155
lvr2::LVRVtkArrow::m_g
double m_g
Definition: LVRVtkArrow.hpp:73
lvr2::Normal< float >
lvr2::LVRVtkArrow::m_b
double m_b
Definition: LVRVtkArrow.hpp:74
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::LVRVtkArrow::m_arrowActor
vtkSmartPointer< vtkActor > m_arrowActor
Definition: LVRVtkArrow.hpp:67
LVRVtkArrow.hpp
lvr2::LVRVtkArrow::restoreColor
void restoreColor()
Definition: LVRVtkArrow.cpp:140
lvr2::LVRVtkArrow::m_endActor
vtkSmartPointer< vtkActor > m_endActor
Definition: LVRVtkArrow.hpp:69
lvr2::LVRVtkArrow::getArrowActor
vtkSmartPointer< vtkActor > getArrowActor()
Definition: LVRVtkArrow.cpp:150
lvr2::LVRVtkArrow::m_startActor
vtkSmartPointer< vtkActor > m_startActor
Definition: LVRVtkArrow.hpp:68
Normal.hpp
lvr2::LVRVtkArrow::~LVRVtkArrow
virtual ~LVRVtkArrow()
Definition: LVRVtkArrow.cpp:165


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:24