ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
HalfEdgeTriangleMesh.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Eigen/Core>
11 #include <unordered_map>
12 
13 // LOCAL
14 #include "ecvMeshBase.h"
15 
16 namespace cloudViewer {
17 namespace geometry {
18 
25 public:
30  class HalfEdge {
31  public:
36  : next_(-1),
37  twin_(-1),
38  vertex_indices_(-1, -1),
39  triangle_index_(-1) {}
40  HalfEdge(const Eigen::Vector2i &vertex_indices,
41  int triangle_index,
42  int next,
43  int twin);
46  bool IsBoundary() const { return twin_ == -1; }
47 
48  public:
50  int next_;
52  int twin_;
57  };
58 
59 public:
63  HalfEdgeTriangleMesh(const char *name = "HalfEdgeTriangleMesh")
64  : ecvMeshBase(name) {}
65 
66  ~HalfEdgeTriangleMesh() override {}
67 
68  // inherited methods (ccHObject)
69  virtual bool isSerializable() const override { return true; }
70  virtual CV_CLASS_ENUM getClassID() const override {
72  }
73 
74 public:
75  virtual HalfEdgeTriangleMesh &clear() override;
76 
77  inline std::size_t edgeSize() const { return half_edges_.size(); }
78 
80  virtual bool hasTriangles() const override {
81  return vertices_.size() > 0 && triangles_.size() > 0;
82  }
83 
85  bool HasTriangleNormals() const {
86  return hasTriangles() && triangles_.size() == triangle_normals_.size();
87  }
88 
90  bool hasHalfEdges() const;
91 
94  std::vector<int> boundaryHalfEdgesFromVertex(int vertex_index) const;
95 
98  std::vector<int> boundaryVerticesFromVertex(int vertex_index) const;
99 
101  std::vector<std::vector<int>> getBoundaries() const;
102 
104 
106 
109  static std::shared_ptr<HalfEdgeTriangleMesh> CreateFromTriangleMesh(
110  const ccMesh &mesh);
111 
112 protected:
116  int nextHalfEdgeFromVertex(int init_half_edge_index) const;
117  int nextHalfEdgeOnBoundary(int curr_half_edge_index) const;
118 
119 public:
121  std::vector<Eigen::Vector3i> triangles_;
123  std::vector<Eigen::Vector3d> triangle_normals_;
125  std::vector<HalfEdge> half_edges_;
126 
129  std::vector<std::vector<int>> ordered_half_edge_from_vertex_;
130 };
131 
132 } // namespace geometry
133 } // namespace cloudViewer
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
Definition: CVTypes.h:97
#define CV_DB_LIB_API
Definition: CV_db.h:15
std::string name
long vertex_index
math::float4 next
Triangular mesh.
Definition: ecvMesh.h:35
HalfEdge class contains vertex, triangle info about a half edge, as well as relations of next and twi...
int next_
Index of the next HalfEdge in the same triangle.
Eigen::Vector2i vertex_indices_
Index of the ordered vertices forming this half edge.
int triangle_index_
Index of the triangle containing this half edge.
HalfEdge(const Eigen::Vector2i &vertex_indices, int triangle_index, int next, int twin)
HalfEdgeTriangleMesh inherits TriangleMesh class with the addition of HalfEdge data structure for eac...
std::vector< int > boundaryVerticesFromVertex(int vertex_index) const
HalfEdgeTriangleMesh(const char *name="HalfEdgeTriangleMesh")
Default Constructor.
std::vector< int > boundaryHalfEdgesFromVertex(int vertex_index) const
virtual bool hasTriangles() const override
Returns true if the mesh contains triangles.
bool HasTriangleNormals() const
Returns true if the mesh contains triangle normals.
std::vector< std::vector< int > > ordered_half_edge_from_vertex_
bool hasHalfEdges() const
Returns true if half-edges have already been computed.
virtual CV_CLASS_ENUM getClassID() const override
Returns class ID.
static std::shared_ptr< HalfEdgeTriangleMesh > CreateFromTriangleMesh(const ccMesh &mesh)
std::vector< Eigen::Vector3i > triangles_
List of triangles in the mesh.
virtual HalfEdgeTriangleMesh & clear() override
std::vector< HalfEdge > half_edges_
List of HalfEdge in the mesh.
virtual bool isSerializable() const override
Returns whether object is serializable of not.
std::vector< std::vector< int > > getBoundaries() const
Returns a vector of boundaries. A boundary is a vector of vertices.
HalfEdgeTriangleMesh operator+(const HalfEdgeTriangleMesh &mesh) const
std::vector< Eigen::Vector3d > triangle_normals_
List of triangle normals in the mesh.
int nextHalfEdgeOnBoundary(int curr_half_edge_index) const
int nextHalfEdgeFromVertex(int init_half_edge_index) const
HalfEdgeTriangleMesh & operator+=(const HalfEdgeTriangleMesh &mesh)
@ HALF_EDGE_MESH
Definition: CVTypes.h:150
Generic file read and write utility for python interface.
Eigen::Matrix< Index, 2, 1 > Vector2i
Definition: knncpp.h:29