LVRModelBridge.cpp
Go to the documentation of this file.
1 
34 #include "LVRModelBridge.hpp"
35 
37 
38 #include <vtkTransform.h>
39 #include <vtkActor.h>
40 #include <vtkProperty.h>
41 
42 namespace lvr2
43 {
44 
45 class LVRMeshBufferBridge;
46 
48  m_pointBridge(new LVRPointBufferBridge(model->m_pointCloud)),
49  m_meshBridge(new LVRMeshBufferBridge(model->m_mesh))
50 {
51  m_pose.p = 0.0;
52  m_pose.r = 0.0;
53  m_pose.t = 0.0;
54  m_pose.x = 0.0;
55  m_pose.y = 0.0;
56  m_pose.z = 0.0;
57  if(validMeshBridge()) {
58  if (!m_meshBridge->hasTextures())
59  {
60  m_meshBridge->getMeshActor()->GetProperty()->BackfaceCullingOff();
61  }
62  else
63  {
64  vtkSmartPointer<vtkProperty> prop = vtkProperty::New();
65  prop->BackfaceCullingOff();
66  m_meshBridge->getTexturedActors()->ApplyProperties(prop);
67  }
68  }
69 }
70 
72 {
75  m_pose = b.m_pose;
76 }
77 
79 {
80  return (m_pointBridge->getNumPoints() > 0) ? true : false;
81 }
82 
84 {
85  return (m_meshBridge->getNumTriangles() > 0) ? true : false;
86 }
87 
88 void LVRModelBridge::setPose(const Pose& pose)
89 {
90  m_pose = pose;
91  vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
92  transform->PostMultiply();
93  transform->RotateX(pose.r);
94  transform->RotateY(pose.t);
95  transform->RotateZ(pose.p);
96  transform->Translate(pose.x, pose.y, pose.z);
97 
98  doStuff(transform);
99 
100 }
101 
103 {
104  vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
105  vtkSmartPointer<vtkMatrix4x4> m = vtkSmartPointer<vtkMatrix4x4>::New();
106 
107  // For some reason we have to copy the matrix
108  // values manually...
109  const double* arr = transform.data();
110  int j = 0;
111  for(int i = 0; i < 16; i++)
112  {
113  if((i % 4) == 0)
114  {
115  j = 0;
116  }
117  double v = arr[i];
118  m->SetElement(i / 4, j, v);
119  j++;
120  }
121 
122  t->PostMultiply();
123  t->SetMatrix(m);
124  doStuff(t);
125 }
126 
127 void LVRModelBridge::doStuff(vtkSmartPointer<vtkTransform> transform)
128 {
129  if(validPointBridge())
130  {
131  m_pointBridge->getPointCloudActor()->SetUserTransform(transform);
132  }
133 
134  if(validMeshBridge())
135  {
136  if (!m_meshBridge->hasTextures())
137  {
138  m_meshBridge->getMeshActor()->SetUserTransform(transform);
139  }
140  else
141  {
142  vtkSmartPointer<vtkActorCollection> col = m_meshBridge->getTexturedActors();
143  col->InitTraversal();
144  for (int i = 0; i < col->GetNumberOfItems(); i++)
145  {
146  col->GetNextActor()->SetUserTransform(transform);
147  }
148  }
149  }
150 }
151 
152 
154 {
155  return m_pose;
156 }
157 
158 void LVRModelBridge::addActors(vtkSmartPointer<vtkRenderer> renderer)
159 {
160  if(validPointBridge())
161  {
162  renderer->AddActor(m_pointBridge->getPointCloudActor());
163  }
164 
165  if(validMeshBridge())
166  {
167  // For simple meshes we only need to add a sigle actor to
168  // render it. For textured meshes we add a actor collection
169  // (one actor per texture).
170  if(!m_meshBridge->hasTextures())
171  {
172  vtkSmartPointer<vtkActor> actor = m_meshBridge->getMeshActor();
173  renderer->AddActor(actor);
174  actor->GetProperty()->BackfaceCullingOff();
175  }
176  else
177  {
178  vtkSmartPointer<vtkActorCollection> collection = m_meshBridge->getTexturedActors();
179  collection->InitTraversal();
180  for(vtkIdType i = 0; i < collection->GetNumberOfItems(); i++)
181  {
182  renderer->AddActor(collection->GetNextActor());
183  }
184 
185  }
186  }
187 }
188 
189 void LVRModelBridge::removeActors(vtkSmartPointer<vtkRenderer> renderer)
190 {
191  if(validPointBridge()) renderer->RemoveActor(m_pointBridge->getPointCloudActor());
192  if(validMeshBridge()) renderer->RemoveActor(m_meshBridge->getMeshActor());
193 }
194 
196 {
197  if(validPointBridge()) m_pointBridge->setVisibility(visible);
198  if(validMeshBridge()) m_meshBridge->setVisibility(visible);
199 }
200 
202 {
203  if(validPointBridge()) m_pointBridge->setNormalsVisibility(visible);
204 }
205 
207 {
208  // TODO Auto-generated destructor stub
209 }
210 
211 } /* namespace lvr2 */
LVRModelBridge(ModelPtr model)
Constructor. Parses the model information and generates vtk actor instances for the given data...
void addActors(vtkSmartPointer< vtkRenderer > renderer)
Adds the generated actors to the given renderer.
void setTransform(const Transformd &transform)
MeshBufferBridgePtr m_meshBridge
void setNormalsVisibility(bool visible)
virtual ~LVRModelBridge()
Destructor.
Main class for conversion of LVR model instances to vtk actors. This class parses the internal model ...
Transform< double > Transformd
4x4 double precision transformation matrix
Definition: MatrixTypes.hpp:71
void removeActors(vtkSmartPointer< vtkRenderer > renderer)
Removes the generated actors from the given renderer.
PointBufferBridgePtr m_pointBridge
void doStuff(vtkSmartPointer< vtkTransform > transform)
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
void setVisibility(bool visible)
void setPose(const Pose &pose)


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 Mon Feb 28 2022 22:46:08