Open3D (C++ API)
HalfEdgeTriangleMesh.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <Eigen/Core>
30 #include <unordered_map>
31 
34 
35 namespace open3d {
36 namespace geometry {
37 
39 public:
40  class HalfEdge {
41  public:
42  HalfEdge() {}
43  HalfEdge(const Eigen::Vector2i &vertex_indices,
44  int triangle_index,
45  int next,
46  int twin);
47  bool IsBoundary() const { return twin_ == -1; }
48 
49  public:
50  // Index of the next HalfEdge
51  int next_ = -1;
52  // Index of the twin HalfEdge
53  int twin_ = -1;
54  // Index of the ordered vertices forming this half edge
55  Eigen::Vector2i vertex_indices_ = Eigen::Vector2i(-1, -1);
56  // Index of the triangle containing this half edge
57  int triangle_index_ = -1;
58  };
59 
60 public:
63 
66  bool ComputeHalfEdges();
67 
69  bool HasHalfEdges() const;
70 
73  std::vector<int> BoundaryHalfEdgesFromVertex(int vertex_index) const;
74 
77  std::vector<int> BoundaryVerticesFromVertex(int vertex_index) const;
78 
80  std::vector<std::vector<int>> GetBoundaries() const;
81 
83  void Clear() override;
84 
85  void RemoveDuplicatedVertices() override;
86  void RemoveDuplicatedTriangles() override;
87  void RemoveUnreferencedVertices() override;
88  void RemoveDegenerateTriangles() override;
89 
91 
93 
94 protected:
96 
97 public:
98  std::vector<HalfEdge> half_edges_;
99 
102  std::vector<std::vector<int>> ordered_half_edge_from_vertex_;
103 
104 protected:
108  int NextHalfEdgeFromVertex(int init_half_edge_index) const;
109  int NextHalfEdgeOnBoundary(int curr_half_edge_index) const;
110 };
111 
112 std::shared_ptr<HalfEdgeTriangleMesh> CreateHalfEdgeMeshFromMesh(
113  const TriangleMesh &mesh);
114 
115 } // namespace geometry
116 } // namespace open3d
std::vector< int > BoundaryHalfEdgesFromVertex(int vertex_index) const
Definition: HalfEdgeTriangleMesh.cpp:177
HalfEdgeTriangleMesh operator+(const HalfEdgeTriangleMesh &mesh) const
Definition: HalfEdgeTriangleMesh.cpp:334
Definition: Geometry.h:32
void RemoveDuplicatedTriangles() override
Definition: HalfEdgeTriangleMesh.cpp:301
std::vector< HalfEdge > half_edges_
Definition: HalfEdgeTriangleMesh.h:98
int NextHalfEdgeOnBoundary(int curr_half_edge_index) const
Definition: HalfEdgeTriangleMesh.cpp:235
std::vector< std::vector< int > > GetBoundaries() const
Returns a vector of boundaries. A boundary is a vector of vertices.
Definition: HalfEdgeTriangleMesh.cpp:211
HalfEdge()
Definition: HalfEdgeTriangleMesh.h:42
std::vector< std::vector< int > > ordered_half_edge_from_vertex_
Definition: HalfEdgeTriangleMesh.h:102
Definition: HalfEdgeTriangleMesh.h:38
long triangle_index
Definition: FilePLY.cpp:117
Eigen::Vector2i vertex_indices_
Definition: HalfEdgeTriangleMesh.h:55
std::shared_ptr< HalfEdgeTriangleMesh > CreateHalfEdgeMeshFromMesh(const TriangleMesh &mesh)
Definition: HalfEdgeTriangleMesh.cpp:265
void RemoveDuplicatedVertices() override
Definition: HalfEdgeTriangleMesh.cpp:293
void Clear() override
Clear all data in HalfEdgeTriangleMesh.
Definition: HalfEdgeTriangleMesh.cpp:44
char type
Definition: FilePCD.cpp:56
long vertex_index
Definition: FilePLY.cpp:44
int NextHalfEdgeFromVertex(int init_half_edge_index) const
Definition: HalfEdgeTriangleMesh.cpp:167
int triangle_index_
Definition: HalfEdgeTriangleMesh.h:57
Definition: PinholeCameraIntrinsic.cpp:34
GeometryType
Definition: Geometry.h:34
HalfEdgeTriangleMesh & operator+=(const HalfEdgeTriangleMesh &mesh)
Definition: HalfEdgeTriangleMesh.cpp:325
int next_
Definition: HalfEdgeTriangleMesh.h:51
HalfEdgeTriangleMesh(Geometry::GeometryType type)
Definition: HalfEdgeTriangleMesh.h:95
int twin_
Definition: HalfEdgeTriangleMesh.h:53
Definition: HalfEdgeTriangleMesh.h:40
bool ComputeHalfEdges()
Definition: HalfEdgeTriangleMesh.cpp:50
bool IsBoundary() const
Definition: HalfEdgeTriangleMesh.h:47
Definition: TriangleMesh.h:43
std::vector< int > BoundaryVerticesFromVertex(int vertex_index) const
Definition: HalfEdgeTriangleMesh.cpp:199
HalfEdgeTriangleMesh()
Definition: HalfEdgeTriangleMesh.h:61
void RemoveDegenerateTriangles() override
Definition: HalfEdgeTriangleMesh.cpp:317
void RemoveUnreferencedVertices() override
Definition: HalfEdgeTriangleMesh.cpp:309
bool HasHalfEdges() const
True if half-edges have already been computed.
Definition: HalfEdgeTriangleMesh.cpp:162