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 
86 
88 
89 protected:
91  void RemoveDuplicatedVertices() override;
92  void RemoveDuplicatedTriangles() override;
93  void RemoveNonManifoldVertices() override;
94  void RemoveNonManifoldTriangles() override;
95 
96 public:
97  std::vector<HalfEdge> half_edges_;
98 
101  std::vector<std::vector<int>> ordered_half_edge_from_vertex_;
102 
103 protected:
107  int NextHalfEdgeFromVertex(int init_half_edge_index) const;
108  int NextHalfEdgeOnBoundary(int curr_half_edge_index) const;
109 };
110 
111 std::shared_ptr<HalfEdgeTriangleMesh> CreateHalfEdgeMeshFromMesh(
112  const TriangleMesh &mesh);
113 
114 } // namespace geometry
115 } // namespace open3d
std::vector< int > BoundaryHalfEdgesFromVertex(int vertex_index) const
Definition: HalfEdgeTriangleMesh.cpp:176
HalfEdgeTriangleMesh operator+(const HalfEdgeTriangleMesh &mesh) const
Definition: HalfEdgeTriangleMesh.cpp:330
Definition: Geometry.h:32
void RemoveDuplicatedTriangles() override
Definition: HalfEdgeTriangleMesh.cpp:297
std::vector< HalfEdge > half_edges_
Definition: HalfEdgeTriangleMesh.h:97
int NextHalfEdgeOnBoundary(int curr_half_edge_index) const
Definition: HalfEdgeTriangleMesh.cpp:234
std::vector< std::vector< int > > GetBoundaries() const
Returns a vector of boundaries. A boundary is a vector of vertices.
Definition: HalfEdgeTriangleMesh.cpp:210
HalfEdge()
Definition: HalfEdgeTriangleMesh.h:42
std::vector< std::vector< int > > ordered_half_edge_from_vertex_
Definition: HalfEdgeTriangleMesh.h:101
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:264
void RemoveDuplicatedVertices() override
Definition: HalfEdgeTriangleMesh.cpp:289
void Clear() override
Clear all data in HalfEdgeTriangleMesh.
Definition: HalfEdgeTriangleMesh.cpp:43
char type
Definition: FilePCD.cpp:56
long vertex_index
Definition: FilePLY.cpp:44
void RemoveNonManifoldVertices() override
Definition: HalfEdgeTriangleMesh.cpp:305
int NextHalfEdgeFromVertex(int init_half_edge_index) const
Definition: HalfEdgeTriangleMesh.cpp:166
int triangle_index_
Definition: HalfEdgeTriangleMesh.h:57
Definition: PinholeCameraIntrinsic.cpp:33
void RemoveNonManifoldTriangles() override
Definition: HalfEdgeTriangleMesh.cpp:313
GeometryType
Definition: Geometry.h:34
HalfEdgeTriangleMesh & operator+=(const HalfEdgeTriangleMesh &mesh)
Definition: HalfEdgeTriangleMesh.cpp:321
int next_
Definition: HalfEdgeTriangleMesh.h:51
HalfEdgeTriangleMesh(Geometry::GeometryType type)
Definition: HalfEdgeTriangleMesh.h:90
int twin_
Definition: HalfEdgeTriangleMesh.h:53
Definition: HalfEdgeTriangleMesh.h:40
bool ComputeHalfEdges()
Definition: HalfEdgeTriangleMesh.cpp:49
bool IsBoundary() const
Definition: HalfEdgeTriangleMesh.h:47
Definition: TriangleMesh.h:39
std::vector< int > BoundaryVerticesFromVertex(int vertex_index) const
Definition: HalfEdgeTriangleMesh.cpp:198
HalfEdgeTriangleMesh()
Definition: HalfEdgeTriangleMesh.h:61
bool HasHalfEdges() const
True if half-edges have already been computed.
Definition: HalfEdgeTriangleMesh.cpp:161