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 
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 */
lvr2::LVRModelBridge::validPointBridge
bool validPointBridge()
Definition: LVRModelBridge.cpp:78
lvr2::LVRModelBridge::m_pointBridge
PointBufferBridgePtr m_pointBridge
Definition: LVRModelBridge.hpp:115
transform
Definition: src/tools/lvr2_transform/Options.cpp:44
lvr2::LVRModelBridge::m_pose
Pose m_pose
Definition: LVRModelBridge.hpp:117
lvr2::LVRMeshBufferBridge
Definition: LVRMeshBufferBridge.hpp:50
lvr2::Pose::t
float t
Definition: LVRModelBridge.hpp:53
lvr2::LVRModelBridge::addActors
void addActors(vtkSmartPointer< vtkRenderer > renderer)
Adds the generated actors to the given renderer.
Definition: LVRModelBridge.cpp:158
lvr2::Transformd
Transform< double > Transformd
4x4 double precision transformation matrix
Definition: MatrixTypes.hpp:71
lvr2::LVRModelBridge::m_meshBridge
MeshBufferBridgePtr m_meshBridge
Definition: LVRModelBridge.hpp:116
lvr2::LVRModelBridge::setPose
void setPose(const Pose &pose)
Definition: LVRModelBridge.cpp:88
lvr2::LVRModelBridge::validMeshBridge
bool validMeshBridge()
Definition: LVRModelBridge.cpp:83
lvr2::LVRModelBridge::getPose
Pose getPose()
Definition: LVRModelBridge.cpp:153
lvr2::Pose::r
float r
Definition: LVRModelBridge.hpp:53
lvr2::LVRModelBridge::removeActors
void removeActors(vtkSmartPointer< vtkRenderer > renderer)
Removes the generated actors from the given renderer.
Definition: LVRModelBridge.cpp:189
lvr2::LVRModelBridge::~LVRModelBridge
virtual ~LVRModelBridge()
Destructor.
Definition: LVRModelBridge.cpp:206
lvr2::LVRModelBridge::LVRModelBridge
LVRModelBridge(ModelPtr model)
Constructor. Parses the model information and generates vtk actor instances for the given data.
Definition: LVRModelBridge.cpp:47
lvr2::LVRPointBufferBridge
Definition: LVRPointBufferBridge.hpp:52
lvr2::Pose::p
float p
Definition: LVRModelBridge.hpp:53
lvr2::LVRModelBridge
Main class for conversion of LVR model instances to vtk actors. This class parses the internal model ...
Definition: LVRModelBridge.hpp:61
Matrix4.hpp
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ModelPtr
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
lvr2::Pose::x
float x
Definition: LVRModelBridge.hpp:53
lvr2::Pose::y
float y
Definition: LVRModelBridge.hpp:53
lvr2::LVRModelBridge::setNormalsVisibility
void setNormalsVisibility(bool visible)
Definition: LVRModelBridge.cpp:201
lvr2::LVRModelBridge::setVisibility
void setVisibility(bool visible)
Definition: LVRModelBridge.cpp:195
lvr2::Pose::z
float z
Definition: LVRModelBridge.hpp:53
lvr2::LVRModelBridge::doStuff
void doStuff(vtkSmartPointer< vtkTransform > transform)
Definition: LVRModelBridge.cpp:127
lvr2::Pose
Definition: LVRModelBridge.hpp:51
LVRModelBridge.hpp
lvr2::LVRModelBridge::setTransform
void setTransform(const Transformd &transform)
Definition: LVRModelBridge.cpp:102


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