Vis 2
Kinetic Visualization for 3D shape and structure
 All Classes Namespaces Functions Pages
HalfedgeMesh.h
1 //Author: Christian Hafner
2 #pragma once
3 
4 #include "AbstractMesh.h"
5 #include <glm/glm.hpp>
6 #include <vector>
7 #include <list>
8 
10 
11 struct HE_Halfedge;
12 
14 {
15  glm::vec3 position;
16 };
17 
18 struct HE_Vertex
19 {
20  HE_Vertex();
21  HE_Vertex(const HE_VertexTraits& traits);
22 
23  HE_Halfedge* outgoing;
24  unsigned index;
25 
26  HE_VertexTraits traits;
27 };
28 
29 struct HE_Face
30 {
31  HE_Face();
32 
33  HE_Halfedge* bounding;
34  unsigned index;
35 
36  std::list<SurfaceAlignedParticle*> associatedParticles;
37 
38  glm::vec3 _normal;
39  glm::vec3 normal() const;
40 };
41 
43 {
44  HE_Halfedge();
45 
46  HE_Halfedge* prev;
47  HE_Halfedge* next;
48  HE_Halfedge* opposite;
49  HE_Face* face;
50  HE_Vertex* toVertex;
51  unsigned index;
52 };
53 
54 class HalfedgeMesh : public AbstractMesh
55 {
56 public:
57  HalfedgeMesh();
58  virtual ~HalfedgeMesh();
59 
60  virtual void init(const MeshDescriptor& descr);
61 
62  unsigned halfedgeCount() const;
63  unsigned vertexCount() const;
64  unsigned faceCount() const;
65 
66  bool removeFace(unsigned fi);
67  bool removeVertex(unsigned vi);
68 
69  HE_Vertex* addVertex(const HE_VertexTraits& traits);
70  HE_Face* addFace(unsigned vi1, unsigned vi2, unsigned vi3);
71 
72  HE_Vertex* vertex(unsigned i);
73  HE_Face* face(unsigned i);
74  HE_Halfedge* halfedge(unsigned i);
75 
76  void convert(AbstractMesh* output, bool computeNormals=false, bool smoothNormals=false) const;
77 
78  void consolidate();
79 
80 private:
81  std::vector<HE_Vertex*> _vertices;
82  std::vector<HE_Face*> _faces;
83  std::vector<HE_Halfedge*> _halfedges;
84 
85  std::list<unsigned> _freeVertexIndices;
86  std::list<unsigned> _freeFaceIndices;
87  std::list<unsigned> _freeHalfedgeIndices;
88 
89  unsigned _numHalfedges;
90  unsigned _numVertices;
91  unsigned _numFaces;
92 
93  HE_Halfedge* findHalfedge(HE_Vertex* fromVertex, HE_Vertex* toVertex);
94  HE_Halfedge* findOutgoingBoundaryHalfedge(HE_Vertex* vertex);
95 
96  void addHalfedgeToList(HE_Halfedge* halfedge);
97  void addFaceToList(HE_Face* face);
98 };
Definition: AbstractMesh.h:5
Definition: MeshDescriptor.h:5
Definition: HalfedgeMesh.h:13
Definition: HalfedgeMesh.h:54
Definition: HalfedgeMesh.h:42
Definition: HalfedgeMesh.h:29
Definition: HalfedgeMesh.h:18
Definition: SurfaceAlignedParticle.h:13