Open3D (C++ API)
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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:
43  : next_(-1),
44  twin_(-1),
45  vertex_indices_(-1, -1),
46  triangle_index_(-1) {}
47  HalfEdge(const Eigen::Vector2i &vertex_indices,
48  int triangle_index,
49  int next,
50  int twin);
51  bool IsBoundary() const { return twin_ == -1; }
52 
53  public:
54  // Index of the next HalfEdge
55  int next_;
56  // Index of the twin HalfEdge
57  int twin_;
58  // Index of the ordered vertices forming this half edge
59  Eigen::Vector2i vertex_indices_;
60  // Index of the triangle containing this half edge
62  };
63 
64 public:
67 
68  virtual HalfEdgeTriangleMesh &Clear() override;
69 
71  bool HasHalfEdges() const;
72 
75  std::vector<int> BoundaryHalfEdgesFromVertex(int vertex_index) const;
76 
79  std::vector<int> BoundaryVerticesFromVertex(int vertex_index) const;
80 
82  std::vector<std::vector<int>> GetBoundaries() const;
83 
85 
87 
88  static std::shared_ptr<HalfEdgeTriangleMesh> CreateFromTriangleMesh(
89  const TriangleMesh &mesh);
90 
91 protected:
93 
97  int NextHalfEdgeFromVertex(int init_half_edge_index) const;
98  int NextHalfEdgeOnBoundary(int curr_half_edge_index) const;
99 
100 public:
101  std::vector<Eigen::Vector3i> triangles_;
102  std::vector<Eigen::Vector3d> triangle_normals_;
103  std::vector<HalfEdge> half_edges_;
104 
107  std::vector<std::vector<int>> ordered_half_edge_from_vertex_;
108 };
109 
110 } // namespace geometry
111 } // namespace open3d
std::vector< int > BoundaryHalfEdgesFromVertex(int vertex_index) const
Definition: HalfEdgeTriangleMesh.cpp:69
std::vector< Eigen::Vector3d > triangle_normals_
Definition: HalfEdgeTriangleMesh.h:102
HalfEdgeTriangleMesh operator+(const HalfEdgeTriangleMesh &mesh) const
Definition: HalfEdgeTriangleMesh.cpp:299
The base geometry class.
Definition: Geometry.h:35
std::vector< HalfEdge > half_edges_
Definition: HalfEdgeTriangleMesh.h:103
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()
Definition: HalfEdgeTriangleMesh.h:42
std::vector< std::vector< int > > ordered_half_edge_from_vertex_
Definition: HalfEdgeTriangleMesh.h:107
Definition: HalfEdgeTriangleMesh.h:38
Definition: MeshBase.h:45
virtual HalfEdgeTriangleMesh & Clear() override
Clear all elements in the geometry.
Definition: HalfEdgeTriangleMesh.cpp:47
Eigen::Vector2i vertex_indices_
Definition: HalfEdgeTriangleMesh.h:59
char type
Definition: FilePCD.cpp:57
long vertex_index
Definition: FilePLY.cpp:45
int NextHalfEdgeFromVertex(int init_half_edge_index) const
Definition: HalfEdgeTriangleMesh.cpp:59
int triangle_index_
Definition: HalfEdgeTriangleMesh.h:61
Definition: PinholeCameraIntrinsic.cpp:34
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:40
HalfEdgeTriangleMesh & operator+=(const HalfEdgeTriangleMesh &mesh)
Definition: HalfEdgeTriangleMesh.cpp:292
int next_
Definition: HalfEdgeTriangleMesh.h:55
HalfEdgeTriangleMesh(Geometry::GeometryType type)
Definition: HalfEdgeTriangleMesh.h:92
int twin_
Definition: HalfEdgeTriangleMesh.h:57
std::vector< Eigen::Vector3i > triangles_
Definition: HalfEdgeTriangleMesh.h:101
Definition: HalfEdgeTriangleMesh.h:40
static std::shared_ptr< HalfEdgeTriangleMesh > CreateFromTriangleMesh(const TriangleMesh &mesh)
Definition: HalfEdgeTriangleMesh.cpp:156
bool IsBoundary() const
Definition: HalfEdgeTriangleMesh.h:51
Definition: TriangleMesh.h:46
std::vector< int > BoundaryVerticesFromVertex(int vertex_index) const
Definition: HalfEdgeTriangleMesh.cpp:89
HalfEdgeTriangleMesh()
Definition: HalfEdgeTriangleMesh.h:65
bool HasHalfEdges() const
True if half-edges have already been computed.
Definition: HalfEdgeTriangleMesh.cpp:54