LVRBoundingBoxBridge.cpp
Go to the documentation of this file.
2 #include "LVRModelBridge.hpp"
3 
4 #include <vtkPolyData.h>
5 #include <vtkPolyDataMapper.h>
6 #include <vtkPoints.h>
7 #include <vtkProperty.h>
8 #include <vtkLine.h>
9 #include <vtkCellArray.h>
10 #include <vtkCellData.h>
11 #include <vtkUnsignedCharArray.h>
12 #include <vtkTransform.h>
13 
14 namespace lvr2
15 {
16 
18 {
19  vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
20  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
21 
22  Vec min = m_boundingBox.getMin();
23  Vec max = m_boundingBox.getMax();
24 
25  float pt[3];
26  // front
27  // 0: bottom left
28  pt[0] = min.x, pt[1] = min.y, pt[2] = min.z;
29  points->InsertNextPoint(pt);
30  // 1: bottom right
31  pt[0] = max.x, pt[1] = min.y, pt[2] = min.z;
32  points->InsertNextPoint(pt);
33  // 2: top left
34  pt[0] = min.x, pt[1] = max.y, pt[2] = min.z;
35  points->InsertNextPoint(pt);
36  // 3: top right
37  pt[0] = max.x, pt[1] = max.y, pt[2] = min.z;
38  points->InsertNextPoint(pt);
39 
40  // back
41  // 4: bottom left
42  pt[0] = min.x, pt[1] = min.y, pt[2] = max.z;
43  points->InsertNextPoint(pt);
44  // 5: bottom right
45  pt[0] = max.x, pt[1] = min.y, pt[2] = max.z;
46  points->InsertNextPoint(pt);
47  // 6: top left
48  pt[0] = min.x, pt[1] = max.y, pt[2] = max.z;
49  points->InsertNextPoint(pt);
50  // 7: top right
51  pt[0] = max.x, pt[1] = max.y, pt[2] = max.z;
52  points->InsertNextPoint(pt);
53 
54  polyData->SetPoints(points);
55 
56  vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
57 
58  // Front
59  // 0
60  vtkSmartPointer<vtkLine> line0 = vtkSmartPointer<vtkLine>::New();
61  line0->GetPointIds()->SetId(0, 0);
62  line0->GetPointIds()->SetId(1, 1);
63  lines->InsertNextCell(line0);
64  // 1
65  vtkSmartPointer<vtkLine> line1 = vtkSmartPointer<vtkLine>::New();
66  line1->GetPointIds()->SetId(0, 0);
67  line1->GetPointIds()->SetId(1, 2);
68  lines->InsertNextCell(line1);
69  // 2
70  vtkSmartPointer<vtkLine> line2 = vtkSmartPointer<vtkLine>::New();
71  line2->GetPointIds()->SetId(0, 3);
72  line2->GetPointIds()->SetId(1, 1);
73  lines->InsertNextCell(line2);
74  // 3
75  vtkSmartPointer<vtkLine> line3 = vtkSmartPointer<vtkLine>::New();
76  line3->GetPointIds()->SetId(0, 3);
77  line3->GetPointIds()->SetId(1, 2);
78  lines->InsertNextCell(line3);
79 
80  // Back
81  // 4
82  vtkSmartPointer<vtkLine> line4 = vtkSmartPointer<vtkLine>::New();
83  line4->GetPointIds()->SetId(0, 4);
84  line4->GetPointIds()->SetId(1, 5);
85  lines->InsertNextCell(line4);
86  // 5
87  vtkSmartPointer<vtkLine> line5 = vtkSmartPointer<vtkLine>::New();
88  line5->GetPointIds()->SetId(0, 4);
89  line5->GetPointIds()->SetId(1, 6);
90  lines->InsertNextCell(line5);
91  // 6
92  vtkSmartPointer<vtkLine> line6 = vtkSmartPointer<vtkLine>::New();
93  line6->GetPointIds()->SetId(0, 7);
94  line6->GetPointIds()->SetId(1, 5);
95  lines->InsertNextCell(line6);
96  // 7
97  vtkSmartPointer<vtkLine> line7 = vtkSmartPointer<vtkLine>::New();
98  line7->GetPointIds()->SetId(0, 7);
99  line7->GetPointIds()->SetId(1, 6);
100  lines->InsertNextCell(line7);
101 
102  // connection front back
103  // 8
104  vtkSmartPointer<vtkLine> line8 = vtkSmartPointer<vtkLine>::New();
105  line8->GetPointIds()->SetId(0, 0);
106  line8->GetPointIds()->SetId(1, 4);
107  lines->InsertNextCell(line8);
108  // 9
109  vtkSmartPointer<vtkLine> line9 = vtkSmartPointer<vtkLine>::New();
110  line9->GetPointIds()->SetId(0, 1);
111  line9->GetPointIds()->SetId(1, 5);
112  lines->InsertNextCell(line9);
113  // 10
114  vtkSmartPointer<vtkLine> line10 = vtkSmartPointer<vtkLine>::New();
115  line10->GetPointIds()->SetId(0, 2);
116  line10->GetPointIds()->SetId(1, 6);
117  lines->InsertNextCell(line10);
118  // 11
119  vtkSmartPointer<vtkLine> line11 = vtkSmartPointer<vtkLine>::New();
120  line11->GetPointIds()->SetId(0, 3);
121  line11->GetPointIds()->SetId(1, 7);
122  lines->InsertNextCell(line11);
123 
124  polyData->SetLines(lines);
125 
126  vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
127  mapper->SetInputData(polyData);
128 
129  m_actor = vtkSmartPointer<vtkActor>::New();
130  m_actor->SetMapper(mapper);
131 
132  setColor(0.0, 1.0, 0.0);
133 }
134 
135 void LVRBoundingBoxBridge::setColor(double r, double g, double b)
136 {
137  double color[] = {r, g, b};
138  m_actor->GetProperty()->SetColor(color);
139 }
140 
142 {
143  vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
144  transform->PostMultiply();
145  transform->RotateX(pose.r);
146  transform->RotateY(pose.t);
147  transform->RotateZ(pose.p);
148  transform->Translate(pose.x, pose.y, pose.z);
149 
150  m_actor->SetUserTransform(transform);
151 }
152 
154 {
155  if (visible)
156  {
157  m_actor->VisibilityOn();
158  }
159  else
160  {
161  m_actor->VisibilityOff();
162  }
163 }
164 
165 } // namespace lvr2
lvr2::BaseVector< float >
transform
Definition: src/tools/lvr2_transform/Options.cpp:44
lvr2::Pose::t
float t
Definition: LVRModelBridge.hpp:53
lvr2::LVRBoundingBoxBridge::setColor
void setColor(double r, double g, double b)
Definition: LVRBoundingBoxBridge.cpp:135
lvr2::color
Definition: DataStruct.hpp:81
lvr2::BaseVector::x
CoordT x
Definition: BaseVector.hpp:65
lvr2::LVRBoundingBoxBridge::setVisibility
void setVisibility(bool visible)
Definition: LVRBoundingBoxBridge.cpp:153
lvr2::Pose::r
float r
Definition: LVRModelBridge.hpp:53
lvr2::BaseVector::y
CoordT y
Definition: BaseVector.hpp:66
lvr2::LVRBoundingBoxBridge::setPose
void setPose(const Pose &pose)
Definition: LVRBoundingBoxBridge.cpp:141
lvr2::LVRBoundingBoxBridge::m_boundingBox
BoundingBox< Vec > m_boundingBox
Definition: LVRBoundingBoxBridge.hpp:30
lvr2::BoundingBox
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
lvr2::LVRBoundingBoxBridge::m_actor
vtkSmartPointer< vtkActor > m_actor
Definition: LVRBoundingBoxBridge.hpp:31
lvr2::BaseVector::z
CoordT z
Definition: BaseVector.hpp:67
lvr2::Pose::p
float p
Definition: LVRModelBridge.hpp:53
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::Pose::x
float x
Definition: LVRModelBridge.hpp:53
lvr2::Pose::y
float y
Definition: LVRModelBridge.hpp:53
LVRBoundingBoxBridge.hpp
lvr2::LVRBoundingBoxBridge::LVRBoundingBoxBridge
LVRBoundingBoxBridge(BoundingBox< Vec > bb)
Definition: LVRBoundingBoxBridge.cpp:17
lvr2::Pose::z
float z
Definition: LVRModelBridge.hpp:53
lvr2::Pose
Definition: LVRModelBridge.hpp:51
LVRModelBridge.hpp


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