| |
| |
| #ifndef MESH_H |
| #define MESH_H |
| |
| |
| #include "list.h" |
| |
| namespace tcg |
| { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| template <typename V, typename E, typename F> |
| class Mesh |
| { |
| public: |
| typedef V vertex_type; |
| typedef E edge_type; |
| typedef F face_type; |
| |
| typedef list<V> vertices_container; |
| typedef list<E> edges_container; |
| typedef list<F> faces_container; |
| |
| protected: |
| vertices_container m_vertices; |
| edges_container m_edges; |
| faces_container m_faces; |
| |
| public: |
| Mesh() {} |
| ~Mesh() {} |
| |
| bool empty() const { return m_vertices.empty(); } |
| void clear() |
| { |
| m_vertices.clear(); |
| m_edges.clear(); |
| m_faces.clear(); |
| } |
| |
| int verticesCount() const { return int(m_vertices.size()); } |
| int edgesCount() const { return int(m_edges.size()); } |
| int facesCount() const { return int(m_faces.size()); } |
| |
| const vertices_container &vertices() const |
| { |
| return m_vertices; |
| } |
| vertices_container &vertices() |
| { |
| return m_vertices; |
| } |
| |
| const edges_container &edges() const |
| { |
| return m_edges; |
| } |
| edges_container &edges() |
| { |
| return m_edges; |
| } |
| |
| const faces_container &faces() const |
| { |
| return m_faces; |
| } |
| faces_container &faces() |
| { |
| return m_faces; |
| } |
| |
| int addVertex(const V &v) |
| { |
| int idx = int(m_vertices.push_back(v)); |
| m_vertices[idx].setIndex(idx); |
| return idx; |
| } |
| int addEdge(const E &e); |
| int addFace(const F &f); |
| |
| void removeVertex(int v); |
| void removeEdge(int e); |
| void removeFace(int f); |
| |
| const V &vertex(int v) const { return m_vertices[v]; } |
| V &vertex(int v) { return m_vertices[v]; } |
| |
| const E &edge(int e) const { return m_edges[e]; } |
| E &edge(int e) { return m_edges[e]; } |
| |
| const F &face(int f) const { return m_faces[f]; } |
| F &face(int f) { return m_faces[f]; } |
| |
| const V &edgeVertex(int e, int i) const |
| { |
| return vertex(edge(e).vertex(i)); |
| } |
| V &edgeVertex(int e, int i) |
| { |
| return vertex(edge(e).vertex(i)); |
| } |
| |
| const F &edgeFace(int e, int i) const |
| { |
| return face(edge(e).face(i)); |
| } |
| F &edgeFace(int e, int i) |
| { |
| return face(edge(e).face(i)); |
| } |
| |
| const V &otherEdgeVertex(int e, int v) const |
| { |
| return vertex(edge(e).otherVertex(v)); |
| } |
| V &otherEdgeVertex(int e, int v) |
| { |
| return vertex(edge(e).otherVertex(v)); |
| } |
| |
| const F &otherEdgeFace(int e, int f) const |
| { |
| return face(edge(e).otherFace(f)); |
| } |
| F &otherEdgeFace(int e, int f) |
| { |
| return face(edge(e).otherFace(f)); |
| } |
| |
| |
| |
| |
| |
| int edgeInciding(int v1, int v2, int n = 0) const; |
| |
| |
| |
| void squeeze(); |
| |
| }; |
| |
| |
| |
| |
| |
| template <typename V, typename E, typename F> |
| class TriMesh : public Mesh<V, E, F> |
| { |
| protected: |
| using Mesh<V, E, F>::m_vertices; |
| using Mesh<V, E, F>::m_edges; |
| using Mesh<V, E, F>::m_faces; |
| |
| public: |
| TriMesh() {} |
| TriMesh(int verticesHint); |
| ~TriMesh() {} |
| |
| int addFace(V &v1, V &v2, V &v3); |
| int addFace(int v1, int v2, int v3) |
| { |
| return addFace(Mesh<V, E, F>::vertex(v1), Mesh<V, E, F>::vertex(v2), Mesh<V, E, F>::vertex(v3)); |
| } |
| |
| int otherFaceVertex(int f, int e) const; |
| int otherFaceVertex(int f, int v1, int v2) const |
| { |
| return otherFaceVertex(f, Mesh<V, E, F>::edgeInciding(v1, v2)); |
| } |
| |
| int otherFaceEdge(int f, int v) const; |
| |
| void faceVertices(int f, int &v1, int &v2, int &v3) const |
| { |
| const E &ed = Mesh<V, E, F>::edge(Mesh<V, E, F>::face(f).edge(0)); |
| v1 = ed.vertex(0); |
| v2 = ed.vertex(1); |
| v3 = otherFaceVertex(f, ed.getIndex()); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| int swapEdge(int e); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| int collapseEdge(int e); |
| |
| |
| |
| |
| |
| |
| |
| int splitEdge(int e); |
| |
| }; |
| |
| } |
| |
| #endif |
| |
| |
| |
| #ifdef INCLUDE_HPP |
| #include "hpp/mesh.hpp" |
| #endif |