MeshUpdateThread.cpp
Go to the documentation of this file.
1 /*
2  * MeshUpdateThread.cpp
3  *
4  * Created on: Jan 29, 2016
5  * Author: twiemann
6  */
7 
8 #include "MeshUpdateThread.hpp"
9 
10 #include <vtkSmartPointer.h>
11 #include <vtkPolyData.h>
12 #include <vtkCellArray.h>
13 #include <vtkPolyDataMapper.h>
14 #include <vtkPoints.h>
15 #include <vtkActor.h>
16 #include <vtkTriangle.h>
17 #include <vtkProperty.h>
18 #include <vtkImageData.h>
19 #include <vtkTexture.h>
20 #include <vtkFloatArray.h>
21 #include <vtkPointData.h>
22 #include <vtkCellData.h>
23 
24 #include <QApplication>
25 
27 {
28  moveToThread(QApplication::instance()->thread());
29  cout << "CREATE" << endl;
30  m_kinfu = kinfu;
31 }
32 
34 {
35  static size_t verts_size = 0;
36  static size_t faces_size = 0;
37  cout << "0" << endl;
38 
39  m_vertices.clear();
40  m_faces.clear();
41 
42  if(meshbuffer)
43  {
44  vtkSmartPointer<vtkPolyData> mesh = vtkSmartPointer<vtkPolyData>::New();
45 
46  // Parse vertex and index buffer
47 
48  size_t slice_size = meshbuffer->getVertices().size() - verts_size;
49  size_t slice_face_size = meshbuffer->getFaces().size() - faces_size;
50 
51  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
52  vtkSmartPointer<vtkCellArray> triangles = vtkSmartPointer<vtkCellArray>::New();
53 
54  vtkSmartPointer<vtkUnsignedCharArray> scalars = vtkSmartPointer<vtkUnsignedCharArray>::New();
55  scalars->SetNumberOfComponents(3);
56  scalars->SetName("Colors");
57 
58 
59  for(size_t k = 0; k < slice_size; k++)
60  {
61  auto vertex = meshbuffer->getVertices()[k + verts_size];
62  m_indexMap[vertex] = k + verts_size;
63  points->InsertNextPoint(
64  vertex->m_position[0],
65  vertex->m_position[1],
66  vertex->m_position[2]);
67 
68  //cout << vertex->m_position[0] << " " << vertex->m_position[1] << " " << vertex->m_position[2] << endl;
69 
70  m_vertices.push_back(vertex->m_position[0]);
71  m_vertices.push_back(vertex->m_position[1]);
72  m_vertices.push_back(vertex->m_position[2]);
73 
74  unsigned char color[3] = {0, 255, 0};
75  scalars->InsertNextTupleValue(color);
76 
77  }
78 
79 
80 
81 
82  mesh->GetPointData()->SetScalars(scalars);
83  cout << "2 " << slice_face_size << endl;
84  for(size_t k = 0; k < slice_face_size; k++)
85  {
86  auto face = meshbuffer->getFaces()[k + faces_size];
87 
88  vtkSmartPointer<vtkTriangle> t = vtkSmartPointer<vtkTriangle>::New();
89  t->GetPointIds()->SetId(0, m_indexMap[face->m_edge->end()]);
90  t->GetPointIds()->SetId(1, m_indexMap[face->m_edge->next()->end()]);
91  t->GetPointIds()->SetId(2, m_indexMap[face->m_edge->next()->next()->end()]);
92  triangles->InsertNextCell(t);
93 
94  m_faces.push_back(m_indexMap[face->m_edge->end()]);
95  m_faces.push_back(m_indexMap[face->m_edge->next()->end()]);
96  m_faces.push_back(m_indexMap[face->m_edge->next()->next()->end()]);
97 
98 
99  int a = m_indexMap[face->m_edge->end()];
100  int b = m_indexMap[face->m_edge->next()->end()];
101  int c = m_indexMap[face->m_edge->next()->next()->end()];
102 
103  cout << a << " " << b << " " << c << " " << m_indexMap.size() << " " << m_vertices.size() / 3 << endl;
104 //
105 // if(a >= m_indexMap.size()) cout << "A: " << a << " / " << m_indexMap.size() << endl;
106 // if(b >= m_indexMap.size()) cout << "B: " << b << " / " << m_indexMap.size() << endl;
107 // if(c >= m_indexMap.size()) cout << "C: " << c << " / " << m_indexMap.size() << endl;
108  }
109 
110  verts_size = meshbuffer->getVertices().size();
111  faces_size = meshbuffer->getFaces().size();
112 
113  mesh->SetPoints(points);
114  mesh->SetPolys(triangles);
115 
116 
117  vtkSmartPointer<vtkPolyDataMapper> mesh_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
118 
119 #ifdef LVR2_USE_VTK5
120  mesh_mapper->SetInput(mesh);
121 #else
122  mesh_mapper->SetInputData(mesh);
123 #endif
124 
125  m_meshActor = vtkActor::New();
126  m_meshActor->SetMapper(mesh_mapper);
127 
128 
129  vtkSmartPointer<vtkProperty> p = vtkSmartPointer<vtkProperty>::New();
130  p->SetColor(1.0, 1.0, 1.0);
131  m_meshActor->SetProperty(p);
132  m_meshActor->VisibilityOn();
133 
134 
135 // vtkSmartPointer<vtkPolyDataMapper> wireframe_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
136 // // wireframe_mapper->SetInputData(mesh); VTK 6
137 // wireframe_mapper->SetInput(mesh);
138 // m_wireframeActor = vtkSmartPointer<vtkActor>::New();
139 // m_wireframeActor->ShallowCopy(m_meshActor);
140 // m_wireframeActor->SetMapper(wireframe_mapper);
141 //
142 // vtkSmartPointer<vtkProperty> p = vtkSmartPointer<vtkProperty>::New();
143 // p->DeepCopy(m_meshActor->GetProperty());
144 // p->SetRepresentationToWireframe();
145 // m_wireframeActor->SetProperty(p);
146 //
147 // float r = 0.0;
148 // float g = 0.9;
149 // float b = 0.0;
150 //
151 // p->DeepCopy(m_meshActor->GetProperty());
152 // p->SetRepresentationToWireframe();
153 // p->SetColor(r, g, b);
154 // m_meshActor->SetProperty(p);
155 //
156 // p = m_wireframeActor->GetProperty();
157 // float inv_r = (float)1 - r;
158 // float inv_g = (float)1 - g;
159 // float inv_b = (float)1 - b;
160 // p->SetColor(inv_r, inv_g, inv_b);
161 // m_wireframeActor->SetProperty(p);
162  }
163 }
164 
166 {
167  while(true)
168  {
169  //auto b = m_kinfu->cyclical().getMesh();
170  //computeMeshActor(b);
171  //Q_EMIT(meshUpdate(m_meshActor));
172  }
173 }
174 
176 {
177  // TODO Auto-generated destructor stub
178 }
179 
180 
MeshUpdateThread.hpp
HMesh
HalfEdgeKinFuMesh< cVertex, lvr::Normal< float > > HMesh
Definition: FusionStage.hpp:62
p
SharedPointer p
Definition: ConvertShared.hpp:42
MeshUpdateThread::~MeshUpdateThread
virtual ~MeshUpdateThread()
Definition: MeshUpdateThread.cpp:175
MeshUpdateThread::m_vertices
vector< float > m_vertices
Definition: MeshUpdateThread.hpp:40
MeshUpdateThread::m_indexMap
unordered_map< VertexPtr, size_t > m_indexMap
Definition: MeshUpdateThread.hpp:36
MeshUpdateThread::run
void run()
Definition: MeshUpdateThread.cpp:165
kfusion::KinFu::Ptr
cv::Ptr< KinFu > Ptr
Definition: kinfu.hpp:25
MeshUpdateThread::m_faces
vector< int > m_faces
Definition: MeshUpdateThread.hpp:41
MeshUpdateThread::m_kinfu
kfusion::KinFu::Ptr m_kinfu
Definition: MeshUpdateThread.hpp:35
mesh
HalfEdgeMesh< Vec > mesh
Definition: src/tools/lvr2_gs_reconstruction/Main.cpp:26
MeshUpdateThread::m_meshActor
vtkActor * m_meshActor
Definition: MeshUpdateThread.hpp:37
MeshUpdateThread::computeMeshActor
void computeMeshActor(HMesh *meshbuffer)
Definition: MeshUpdateThread.cpp:33
MeshUpdateThread::MeshUpdateThread
MeshUpdateThread(kfusion::KinFu::Ptr kinfu)
Definition: MeshUpdateThread.cpp:26


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