MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
mesh.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#ifndef MVE_TRIANGLE_MESH_HEADER
11#define MVE_TRIANGLE_MESH_HEADER
12
13#include <vector>
14#include <memory>
15
16#include "math/vector.h"
17#include "mve/defines.h"
18
20
27{
28public:
29 typedef std::shared_ptr<MeshBase> Ptr;
30 typedef std::shared_ptr<MeshBase const> ConstPtr;
31
32 typedef unsigned int VertexID;
33 typedef std::vector<math::Vec3f> VertexList;
34 typedef std::vector<math::Vec4f> ColorList;
35 typedef std::vector<float> ConfidenceList;
36 typedef std::vector<float> ValueList;
37
38public:
39 virtual ~MeshBase (void);
40
42 VertexList const& get_vertices (void) const;
44 VertexList& get_vertices (void);
45
47 ColorList const& get_vertex_colors (void) const;
49 ColorList& get_vertex_colors (void);
50
52 ConfidenceList const& get_vertex_confidences (void) const;
54 ConfidenceList& get_vertex_confidences (void);
55
57 ValueList const& get_vertex_values (void) const;
59 ValueList& get_vertex_values (void);
60
62 bool has_vertex_colors (void) const;
64 bool has_vertex_confidences (void) const;
66 bool has_vertex_values (void) const;
67
69 virtual void clear (void);
70
71protected:
72 MeshBase (void);
73
74protected:
79};
80
81/* ---------------------------------------------------------------- */
82
89class TriangleMesh : public MeshBase
90{
91public:
92 typedef std::shared_ptr<TriangleMesh> Ptr;
93 typedef std::shared_ptr<TriangleMesh const> ConstPtr;
94
95 typedef std::vector<math::Vec3f> NormalList;
96 typedef std::vector<math::Vec2f> TexCoordList;
97 typedef std::vector<VertexID> FaceList;
98
99 typedef std::vector<bool> DeleteList;
100
101public:
102 virtual ~TriangleMesh (void);
103 static Ptr create (void);
104 static Ptr create (TriangleMesh::ConstPtr other);
105
106 Ptr duplicate (void) const;
107
109 NormalList const& get_vertex_normals (void) const;
111 NormalList& get_vertex_normals (void);
112
114 TexCoordList const& get_vertex_texcoords (void) const;
116 TexCoordList& get_vertex_texcoords (void);
117
119 FaceList const& get_faces (void) const;
121 FaceList& get_faces (void);
122
124 NormalList const& get_face_normals (void) const;
126 NormalList& get_face_normals (void);
127
129 ColorList const& get_face_colors (void) const;
131 ColorList& get_face_colors (void);
132
134 bool has_vertex_normals (void) const;
136 bool has_vertex_texcoords (void) const;
138 bool has_face_normals (void) const;
140 bool has_face_colors (void) const;
141
143 void ensure_normals (bool face = true, bool vertex = true);
145 void recalc_normals (bool face = true, bool vertex = true);
146
148 virtual void clear (void);
150 void clear_normals (void);
151
156 void delete_vertices (DeleteList const& dlist);
157
158 /*
159 * Deletes marked vertices and related attributes, deletes faces
160 * referencing marked vertices and fixes face indices.
161 */
162 void delete_vertices_fix_faces (DeleteList const& dlist);
163
168 void delete_invalid_faces (void);
169
171 std::size_t get_byte_size (void) const;
172
173protected:
176
180
181protected:
183 TriangleMesh (void);
184};
185
186/* ---------------------------------------------------------------- */
187
188inline
189MeshBase::MeshBase (void)
190{
191}
192
193inline
194MeshBase::~MeshBase (void)
195{
196}
197
198inline MeshBase::VertexList const&
199MeshBase::get_vertices (void) const
200{
201 return this->vertices;
202}
203
205MeshBase::get_vertices (void)
206{
207 return this->vertices;
208}
209
210inline MeshBase::ColorList const&
211MeshBase::get_vertex_colors (void) const
212{
213 return this->vertex_colors;
214}
215
217MeshBase::get_vertex_colors (void)
218{
219 return this->vertex_colors;
220}
221
222inline MeshBase::ConfidenceList const&
223MeshBase::get_vertex_confidences (void) const
224{
225 return this->vertex_confidences;
226}
227
229MeshBase::get_vertex_confidences (void)
230{
231 return this->vertex_confidences;
232}
233
234inline MeshBase::ValueList const&
235MeshBase::get_vertex_values (void) const
236{
237 return this->vertex_values;
238}
239
241MeshBase::get_vertex_values (void)
242{
243 return this->vertex_values;
244}
245
246inline void
247MeshBase::clear (void)
248{
249 this->vertices.clear();
250 this->vertex_colors.clear();
251 this->vertex_confidences.clear();
252 this->vertex_values.clear();
253}
254
255inline bool
256MeshBase::has_vertex_colors (void) const
257{
258 return !this->vertices.empty()
259 && this->vertex_colors.size() == this->vertices.size();
260}
261
262inline bool
263MeshBase::has_vertex_confidences (void) const
264{
265 return !this->vertices.empty()
266 && this->vertex_confidences.size() == this->vertices.size();
267}
268
269inline bool
270MeshBase::has_vertex_values (void) const
271{
272 return !this->vertices.empty()
273 && this->vertex_values.size() == this->vertices.size();
274}
275
276/* ---------------------------------------------------------------- */
277
279TriangleMesh::duplicate (void) const
280{
281 return Ptr(new TriangleMesh(*this));
282}
283
284inline
285TriangleMesh::TriangleMesh (void)
286{
287}
288
289inline
290TriangleMesh::~TriangleMesh (void)
291{
292}
293
295TriangleMesh::create (void)
296{
297 return Ptr(new TriangleMesh);
298}
299
301TriangleMesh::create (TriangleMesh::ConstPtr other)
302{
303 return Ptr(new TriangleMesh(*other));
304}
305
306inline TriangleMesh::NormalList const&
307TriangleMesh::get_vertex_normals (void) const
308{
309 return this->vertex_normals;
310}
311
313TriangleMesh::get_vertex_normals (void)
314{
315 return this->vertex_normals;
316}
317
318inline TriangleMesh::TexCoordList const&
319TriangleMesh::get_vertex_texcoords (void) const
320{
321 return this->vertex_texcoords;
322}
323
325TriangleMesh::get_vertex_texcoords (void)
326{
327 return this->vertex_texcoords;
328}
329
330inline TriangleMesh::FaceList const&
331TriangleMesh::get_faces (void) const
332{
333 return this->faces;
334}
335
337TriangleMesh::get_faces (void)
338{
339 return this->faces;
340}
341
342inline TriangleMesh::NormalList const&
343TriangleMesh::get_face_normals (void) const
344{
345 return this->face_normals;
346}
347
349TriangleMesh::get_face_normals (void)
350{
351 return this->face_normals;
352}
353
355TriangleMesh::get_face_colors (void)
356{
357 return this->face_colors;
358}
359
360inline TriangleMesh::ColorList const&
361TriangleMesh::get_face_colors (void) const
362{
363 return this->face_colors;
364}
365
366inline void
367TriangleMesh::clear_normals (void)
368{
369 this->vertex_normals.clear();
370 this->face_normals.clear();
371}
372
373inline void
374TriangleMesh::clear (void)
375{
376 this->MeshBase::clear();
377 this->vertex_normals.clear();
378 this->vertex_texcoords.clear();
379 this->faces.clear();
380 this->face_normals.clear();
381 this->face_colors.clear();
382}
383
384inline bool
385TriangleMesh::has_vertex_normals (void) const
386{
387 return !this->vertices.empty()
388 && this->vertex_normals.size() == this->vertices.size();
389}
390
391inline bool
392TriangleMesh::has_vertex_texcoords (void) const
393{
394 return !this->vertices.empty()
395 && this->vertex_texcoords.size() == this->vertices.size();
396}
397
398inline bool
399TriangleMesh::has_face_normals (void) const
400{
401 return !this->faces.empty()
402 && this->faces.size() == this->face_normals.size() * 3;
403}
404
405inline bool
406TriangleMesh::has_face_colors (void) const
407{
408 return !this->faces.empty()
409 && this->faces.size() == this->face_colors.size() * 3;
410}
411
413
414#endif /* MVE_TRIANGLE_MESH_HEADER */
Base class for meshes.
Definition mesh.h:27
std::vector< math::Vec3f > VertexList
Definition mesh.h:33
ConfidenceList vertex_confidences
Definition mesh.h:77
ValueList vertex_values
Definition mesh.h:78
ColorList vertex_colors
Definition mesh.h:76
std::shared_ptr< MeshBase > Ptr
Definition mesh.h:29
VertexList vertices
Definition mesh.h:75
std::shared_ptr< MeshBase const > ConstPtr
Definition mesh.h:30
std::vector< float > ConfidenceList
Definition mesh.h:35
std::vector< math::Vec4f > ColorList
Definition mesh.h:34
unsigned int VertexID
Definition mesh.h:32
std::vector< float > ValueList
Definition mesh.h:36
Triangle mesh representation.
Definition mesh.h:90
std::vector< math::Vec3f > NormalList
Definition mesh.h:95
std::vector< bool > DeleteList
Definition mesh.h:99
FaceList faces
Definition mesh.h:177
TexCoordList vertex_texcoords
Definition mesh.h:175
std::vector< math::Vec2f > TexCoordList
Definition mesh.h:96
std::shared_ptr< TriangleMesh > Ptr
Definition mesh.h:92
std::vector< VertexID > FaceList
Definition mesh.h:97
std::shared_ptr< TriangleMesh const > ConstPtr
Definition mesh.h:93
NormalList vertex_normals
Definition mesh.h:174
NormalList face_normals
Definition mesh.h:178
ColorList face_colors
Definition mesh.h:179
#define MVE_NAMESPACE_BEGIN
Definition defines.h:13
#define MVE_NAMESPACE_END
Definition defines.h:14