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 
38 // TODO likely broken
40 public:
41  class HalfEdge {
42  public:
44  : next_(-1),
45  twin_(-1),
46  vertex_indices_(-1, -1),
47  triangle_index_(-1) {}
48  HalfEdge(const Eigen::Vector2i &vertex_indices,
49  int triangle_index,
50  int next,
51  int twin);
52  bool IsBoundary() const { return twin_ == -1; }
53 
54  public:
55  // Index of the next HalfEdge
56  int next_;
57  // Index of the twin HalfEdge
58  int twin_;
59  // Index of the ordered vertices forming this half edge
60  Eigen::Vector2i vertex_indices_;
61  // Index of the triangle containing this half edge
63  };
64 
65 public:
68 
70  HalfEdgeTriangleMesh &Clear() override;
71  bool IsEmpty() const override;
72  Eigen::Vector3d GetMinBound() const override;
73  Eigen::Vector3d GetMaxBound() const override;
74  Eigen::Vector3d GetCenter() const override;
78  const Eigen::Matrix4d &transformation) override;
79  HalfEdgeTriangleMesh &Translate(const Eigen::Vector3d &translation,
80  bool relative = true) override;
81  HalfEdgeTriangleMesh &Scale(const double scale,
82  bool center = true) override;
84  const Eigen::Vector3d &rotation,
85  bool center = true,
87 
90  bool ComputeHalfEdges();
91 
92  bool HasVertices() const { return vertices_.size() > 0; }
93 
95  bool HasHalfEdges() const;
96 
99  std::vector<int> BoundaryHalfEdgesFromVertex(int vertex_index) const;
100 
103  std::vector<int> BoundaryVerticesFromVertex(int vertex_index) const;
104 
106  std::vector<std::vector<int>> GetBoundaries() const;
107 
112 
114 
116 
117  static std::shared_ptr<HalfEdgeTriangleMesh> CreateFromMesh(
118  const TriangleMesh &mesh);
119 
120 protected:
122 
126  int NextHalfEdgeFromVertex(int init_half_edge_index) const;
127  int NextHalfEdgeOnBoundary(int curr_half_edge_index) const;
128 
129 public:
130  std::vector<Eigen::Vector3d> vertices_;
131  std::vector<Eigen::Vector3d> vertex_normals_;
132  std::vector<Eigen::Vector3d> vertex_colors_;
133  std::vector<Eigen::Vector3i> triangles_;
134  std::vector<Eigen::Vector3d> triangle_normals_;
135  std::vector<std::unordered_set<int>> adjacency_list_;
136 
137  std::vector<HalfEdge> half_edges_;
138 
141  std::vector<std::vector<int>> ordered_half_edge_from_vertex_;
142 };
143 
144 } // namespace geometry
145 } // namespace open3d
std::vector< int > BoundaryHalfEdgesFromVertex(int vertex_index) const
Definition: HalfEdgeTriangleMesh.cpp:181
std::vector< Eigen::Vector3d > triangle_normals_
Definition: HalfEdgeTriangleMesh.h:134
HalfEdgeTriangleMesh operator+(const HalfEdgeTriangleMesh &mesh) const
Definition: HalfEdgeTriangleMesh.cpp:392
Definition: Geometry.h:32
bool HasVertices() const
Definition: HalfEdgeTriangleMesh.h:92
std::vector< HalfEdge > half_edges_
Definition: HalfEdgeTriangleMesh.h:137
HalfEdgeTriangleMesh & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Definition: HalfEdgeTriangleMesh.cpp:269
int NextHalfEdgeOnBoundary(int curr_half_edge_index) const
Definition: HalfEdgeTriangleMesh.cpp:289
Definition: BoundingVolume.h:90
bool IsEmpty() const override
Definition: HalfEdgeTriangleMesh.cpp:239
std::vector< std::vector< int > > GetBoundaries() const
Returns a vector of boundaries. A boundary is a vector of vertices.
Definition: HalfEdgeTriangleMesh.cpp:215
HalfEdge()
Definition: HalfEdgeTriangleMesh.h:43
HalfEdgeTriangleMesh & Transform(const Eigen::Matrix4d &transformation) override
Definition: HalfEdgeTriangleMesh.cpp:261
OrientedBoundingBox GetOrientedBoundingBox() const override
Definition: HalfEdgeTriangleMesh.cpp:257
std::vector< std::vector< int > > ordered_half_edge_from_vertex_
Definition: HalfEdgeTriangleMesh.h:141
Definition: HalfEdgeTriangleMesh.h:39
static std::shared_ptr< HalfEdgeTriangleMesh > CreateFromMesh(const TriangleMesh &mesh)
Definition: HalfEdgeTriangleMesh.cpp:319
Definition: BoundingVolume.h:38
RotationType
Definition: Geometry3D.h:43
std::vector< Eigen::Vector3d > vertex_colors_
Definition: HalfEdgeTriangleMesh.h:132
HalfEdgeTriangleMesh & Clear() override
Clear all data in HalfEdgeTriangleMesh.
Definition: HalfEdgeTriangleMesh.cpp:47
Eigen::Vector2i vertex_indices_
Definition: HalfEdgeTriangleMesh.h:60
Definition: Geometry3D.h:41
HalfEdgeTriangleMesh & RemoveDuplicatedTriangles()
Definition: HalfEdgeTriangleMesh.cpp:356
AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Definition: HalfEdgeTriangleMesh.cpp:253
Eigen::Vector3d GetMinBound() const override
Definition: HalfEdgeTriangleMesh.cpp:241
Eigen::Vector3d GetMaxBound() const override
Definition: HalfEdgeTriangleMesh.cpp:245
HalfEdgeTriangleMesh & Rotate(const Eigen::Vector3d &rotation, bool center=true, RotationType type=RotationType::XYZ) override
Definition: HalfEdgeTriangleMesh.cpp:281
HalfEdgeTriangleMesh & RemoveDuplicatedVertices()
Definition: HalfEdgeTriangleMesh.cpp:347
char type
Definition: FilePCD.cpp:56
HalfEdgeTriangleMesh & RemoveDegenerateTriangles()
Definition: HalfEdgeTriangleMesh.cpp:374
long vertex_index
Definition: FilePLY.cpp:45
int NextHalfEdgeFromVertex(int init_half_edge_index) const
Definition: HalfEdgeTriangleMesh.cpp:171
int triangle_index_
Definition: HalfEdgeTriangleMesh.h:62
Definition: PinholeCameraIntrinsic.cpp:34
HalfEdgeTriangleMesh & Scale(const double scale, bool center=true) override
Definition: HalfEdgeTriangleMesh.cpp:275
Eigen::Vector3d GetCenter() const override
Definition: HalfEdgeTriangleMesh.cpp:249
GeometryType
Definition: Geometry.h:34
HalfEdgeTriangleMesh & operator+=(const HalfEdgeTriangleMesh &mesh)
Definition: HalfEdgeTriangleMesh.cpp:383
int next_
Definition: HalfEdgeTriangleMesh.h:56
HalfEdgeTriangleMesh(Geometry::GeometryType type)
Definition: HalfEdgeTriangleMesh.h:121
int twin_
Definition: HalfEdgeTriangleMesh.h:58
std::vector< Eigen::Vector3i > triangles_
Definition: HalfEdgeTriangleMesh.h:133
Definition: HalfEdgeTriangleMesh.h:41
bool ComputeHalfEdges()
Definition: HalfEdgeTriangleMesh.cpp:54
HalfEdgeTriangleMesh & RemoveUnreferencedVertices()
Definition: HalfEdgeTriangleMesh.cpp:365
bool IsBoundary() const
Definition: HalfEdgeTriangleMesh.h:52
Definition: TriangleMesh.h:43
std::vector< int > BoundaryVerticesFromVertex(int vertex_index) const
Definition: HalfEdgeTriangleMesh.cpp:203
std::vector< std::unordered_set< int > > adjacency_list_
Definition: HalfEdgeTriangleMesh.h:135
std::vector< Eigen::Vector3d > vertices_
Definition: HalfEdgeTriangleMesh.h:130
HalfEdgeTriangleMesh()
Definition: HalfEdgeTriangleMesh.h:66
std::vector< Eigen::Vector3d > vertex_normals_
Definition: HalfEdgeTriangleMesh.h:131
bool HasHalfEdges() const
True if half-edges have already been computed.
Definition: HalfEdgeTriangleMesh.cpp:166