Open3D (C++ API)  0.16.0
MeshBase.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-2021 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 <memory>
31#include <tuple>
32#include <unordered_map>
33#include <unordered_set>
34#include <vector>
35
38
39namespace open3d {
40namespace geometry {
41
42class PointCloud;
43class TriangleMesh;
44
51class MeshBase : public Geometry3D {
52public:
61 enum class SimplificationContraction { Average, Quadric };
62
70 enum class FilterScope { All, Color, Normal, Vertex };
71
76 enum class DeformAsRigidAsPossibleEnergy { Spokes, Smoothed };
77
80 ~MeshBase() override {}
81
82public:
83 virtual MeshBase &Clear() override;
84 virtual bool IsEmpty() const override;
85 virtual Eigen::Vector3d GetMinBound() const override;
86 virtual Eigen::Vector3d GetMaxBound() const override;
87 virtual Eigen::Vector3d GetCenter() const override;
90 bool robust = false) const override;
91 virtual MeshBase &Transform(const Eigen::Matrix4d &transformation) override;
92 virtual MeshBase &Translate(const Eigen::Vector3d &translation,
93 bool relative = true) override;
94 virtual MeshBase &Scale(const double scale,
95 const Eigen::Vector3d &center) override;
96 virtual MeshBase &Rotate(const Eigen::Matrix3d &R,
97 const Eigen::Vector3d &center) override;
98
99 MeshBase &operator+=(const MeshBase &mesh);
100 MeshBase operator+(const MeshBase &mesh) const;
101
103 bool HasVertices() const { return vertices_.size() > 0; }
104
106 bool HasVertexNormals() const {
107 return vertices_.size() > 0 &&
108 vertex_normals_.size() == vertices_.size();
109 }
110
112 bool HasVertexColors() const {
113 return vertices_.size() > 0 &&
114 vertex_colors_.size() == vertices_.size();
115 }
116
119 for (size_t i = 0; i < vertex_normals_.size(); i++) {
120 vertex_normals_[i].normalize();
121 if (std::isnan(vertex_normals_[i](0))) {
122 vertex_normals_[i] = Eigen::Vector3d(0.0, 0.0, 1.0);
123 }
124 }
125 return *this;
126 }
127
131 MeshBase &PaintUniformColor(const Eigen::Vector3d &color) {
133 return *this;
134 }
135
137 std::tuple<std::shared_ptr<TriangleMesh>, std::vector<size_t>>
138 ComputeConvexHull() const;
139
140protected:
141 // Forward child class type to avoid indirect nonvirtual base
144 const std::vector<Eigen::Vector3d> &vertices)
145 : Geometry3D(type), vertices_(vertices) {}
146
147public:
149 std::vector<Eigen::Vector3d> vertices_;
151 std::vector<Eigen::Vector3d> vertex_normals_;
153 std::vector<Eigen::Vector3d> vertex_colors_;
154};
155
156} // namespace geometry
157} // namespace open3d
math::float4 color
Definition: LineSetBuffers.cpp:64
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:155
The base geometry class for 3D geometries.
Definition: Geometry3D.h:47
void ResizeAndPaintUniformColor(std::vector< Eigen::Vector3d > &colors, const size_t size, const Eigen::Vector3d &color) const
Resizes the colors vector and paints a uniform color.
Definition: Geometry3D.cpp:75
The base geometry class.
Definition: Geometry.h:37
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:42
MeshBash Class.
Definition: MeshBase.h:51
std::vector< Eigen::Vector3d > vertices_
Vertex coordinates.
Definition: MeshBase.h:149
MeshBase & NormalizeNormals()
Normalize vertex normals to length 1.
Definition: MeshBase.h:118
MeshBase(Geometry::GeometryType type)
Definition: MeshBase.h:142
virtual bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: MeshBase.cpp:52
MeshBase & PaintUniformColor(const Eigen::Vector3d &color)
Assigns each vertex in the TriangleMesh the same color.
Definition: MeshBase.h:131
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: MeshBase.cpp:58
bool HasVertexNormals() const
Returns True if the mesh contains vertex normals.
Definition: MeshBase.h:106
virtual MeshBase & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &center) override
Apply rotation to the geometry coordinates and normals. Given a rotation matrix , and center ,...
Definition: MeshBase.cpp:89
std::vector< Eigen::Vector3d > vertex_colors_
RGB colors of vertices.
Definition: MeshBase.h:153
MeshBase(Geometry::GeometryType type, const std::vector< Eigen::Vector3d > &vertices)
Definition: MeshBase.h:143
MeshBase & operator+=(const MeshBase &mesh)
Definition: MeshBase.cpp:96
virtual MeshBase & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: MeshBase.cpp:72
DeformAsRigidAsPossibleEnergy
Definition: MeshBase.h:76
~MeshBase() override
Definition: MeshBase.h:80
bool HasVertexColors() const
Returns True if the mesh contains vertex colors.
Definition: MeshBase.h:112
MeshBase()
Default Constructor.
Definition: MeshBase.h:79
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
Definition: MeshBase.cpp:64
SimplificationContraction
Indicates the method that is used for mesh simplification if multiple vertices are combined to a sing...
Definition: MeshBase.h:61
std::tuple< std::shared_ptr< TriangleMesh >, std::vector< size_t > > ComputeConvexHull() const
Function that computes the convex hull of the triangle mesh using qhull.
Definition: MeshBase.cpp:126
virtual MeshBase & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: MeshBase.cpp:78
bool HasVertices() const
Returns True if the mesh contains vertices.
Definition: MeshBase.h:103
virtual MeshBase & Clear() override
Clear all elements in the geometry.
Definition: MeshBase.cpp:45
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: MeshBase.cpp:62
MeshBase operator+(const MeshBase &mesh) const
Definition: MeshBase.cpp:121
virtual MeshBase & Scale(const double scale, const Eigen::Vector3d &center) override
Apply scaling to the geometry coordinates. Given a scaling factor , and center , a given point is tr...
Definition: MeshBase.cpp:84
std::vector< Eigen::Vector3d > vertex_normals_
Vertex normals.
Definition: MeshBase.h:151
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: MeshBase.cpp:54
virtual OrientedBoundingBox GetOrientedBoundingBox(bool robust=false) const override
Definition: MeshBase.cpp:68
FilterScope
Indicates the scope of filter operations.
Definition: MeshBase.h:70
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:44
Definition: TriangleMeshSimplification.cpp:41
char type
Definition: FilePCD.cpp:60
Definition: PinholeCameraIntrinsic.cpp:35