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 
44 public:
49  class HalfEdge {
50  public:
55  : next_(-1),
56  twin_(-1),
57  vertex_indices_(-1, -1),
58  triangle_index_(-1) {}
59  HalfEdge(const Eigen::Vector2i &vertex_indices,
60  int triangle_index,
61  int next,
62  int twin);
65  bool IsBoundary() const { return twin_ == -1; }
66 
67  public:
69  int next_;
71  int twin_;
73  Eigen::Vector2i vertex_indices_;
76  };
77 
78 public:
84 
85  virtual HalfEdgeTriangleMesh &Clear() override;
86 
88  bool HasHalfEdges() const;
89 
92  std::vector<int> BoundaryHalfEdgesFromVertex(int vertex_index) const;
93 
96  std::vector<int> BoundaryVerticesFromVertex(int vertex_index) const;
97 
99  std::vector<std::vector<int>> GetBoundaries() const;
100 
102 
104 
107  static std::shared_ptr<HalfEdgeTriangleMesh> CreateFromTriangleMesh(
108  const TriangleMesh &mesh);
109 
110 protected:
117 
121  int NextHalfEdgeFromVertex(int init_half_edge_index) const;
122  int NextHalfEdgeOnBoundary(int curr_half_edge_index) const;
123 
124 public:
126  std::vector<Eigen::Vector3i> triangles_;
128  std::vector<Eigen::Vector3d> triangle_normals_;
130  std::vector<HalfEdge> half_edges_;
131 
134  std::vector<std::vector<int>> ordered_half_edge_from_vertex_;
135 };
136 
137 } // namespace geometry
138 } // namespace open3d
std::vector< int > BoundaryHalfEdgesFromVertex(int vertex_index) const
Definition: HalfEdgeTriangleMesh.cpp:69
std::vector< Eigen::Vector3d > triangle_normals_
List of triangle normals in the mesh.
Definition: HalfEdgeTriangleMesh.h:128
HalfEdgeTriangleMesh operator+(const HalfEdgeTriangleMesh &mesh) const
Definition: HalfEdgeTriangleMesh.cpp:299
The base geometry class.
Definition: Geometry.h:37
std::vector< HalfEdge > half_edges_
List of HalfEdge in the mesh.
Definition: HalfEdgeTriangleMesh.h:130
int NextHalfEdgeOnBoundary(int curr_half_edge_index) const
Definition: HalfEdgeTriangleMesh.cpp:125
std::vector< std::vector< int > > GetBoundaries() const
Returns a vector of boundaries. A boundary is a vector of vertices.
Definition: HalfEdgeTriangleMesh.cpp:101
HalfEdge()
Default Constructor.
Definition: HalfEdgeTriangleMesh.h:54
std::vector< std::vector< int > > ordered_half_edge_from_vertex_
Definition: HalfEdgeTriangleMesh.h:134
HalfEdgeTriangleMesh inherits TriangleMesh class with the addition of HalfEdge data structure for eac...
Definition: HalfEdgeTriangleMesh.h:43
MeshBash Class.
Definition: MeshBase.h:51
virtual HalfEdgeTriangleMesh & Clear() override
Clear all elements in the geometry.
Definition: HalfEdgeTriangleMesh.cpp:47
Eigen::Vector2i vertex_indices_
Index of the ordered vertices forming this half edge.
Definition: HalfEdgeTriangleMesh.h:73
char type
Definition: FilePCD.cpp:58
long vertex_index
Definition: FilePLY.cpp:46
int NextHalfEdgeFromVertex(int init_half_edge_index) const
Definition: HalfEdgeTriangleMesh.cpp:59
int triangle_index_
Index of the triangle containing this half edge.
Definition: HalfEdgeTriangleMesh.h:75
Definition: Open3DViewer.h:29
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:42
HalfEdgeTriangleMesh & operator+=(const HalfEdgeTriangleMesh &mesh)
Definition: HalfEdgeTriangleMesh.cpp:292
int next_
Index of the next HalfEdge in the same triangle.
Definition: HalfEdgeTriangleMesh.h:69
HalfEdgeTriangleMesh(Geometry::GeometryType type)
Parameterized Constructor.
Definition: HalfEdgeTriangleMesh.h:116
int twin_
Index of the twin HalfEdge.
Definition: HalfEdgeTriangleMesh.h:71
std::vector< Eigen::Vector3i > triangles_
List of triangles in the mesh.
Definition: HalfEdgeTriangleMesh.h:126
HalfEdge class contains vertex, triangle info about a half edge, as well as relations of next and twi...
Definition: HalfEdgeTriangleMesh.h:49
static std::shared_ptr< HalfEdgeTriangleMesh > CreateFromTriangleMesh(const TriangleMesh &mesh)
Definition: HalfEdgeTriangleMesh.cpp:156
bool IsBoundary() const
Definition: HalfEdgeTriangleMesh.h:65
Triangle mesh contains vertices and triangles represented by the indices to the vertices.
Definition: TriangleMesh.h:54
std::vector< int > BoundaryVerticesFromVertex(int vertex_index) const
Definition: HalfEdgeTriangleMesh.cpp:89
HalfEdgeTriangleMesh()
Default Constructor.
Definition: HalfEdgeTriangleMesh.h:82
bool HasHalfEdges() const
Returns true if half-edges have already been computed.
Definition: HalfEdgeTriangleMesh.cpp:54