Open3D (C++ API)  0.18.0+5c982c7
MeshBase.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Eigen/Core>
11 #include <memory>
12 #include <tuple>
13 #include <unordered_map>
14 #include <unordered_set>
15 #include <vector>
16 
18 #include "open3d/utility/Helper.h"
19 
20 namespace open3d {
21 namespace geometry {
22 
23 class PointCloud;
24 class TriangleMesh;
25 
32 class MeshBase : public Geometry3D {
33 public:
43 
51  enum class FilterScope { All, Color, Normal, Vertex };
52 
58 
61  ~MeshBase() override {}
62 
63 public:
64  virtual MeshBase &Clear() override;
65  virtual bool IsEmpty() const override;
66  virtual Eigen::Vector3d GetMinBound() const override;
67  virtual Eigen::Vector3d GetMaxBound() const override;
68  virtual Eigen::Vector3d GetCenter() const override;
69 
72  virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override;
73 
80  bool robust = false) const override;
81 
89  bool robust = false) const override;
90 
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 
140 protected:
141  // Forward child class type to avoid indirect nonvirtual base
144  const std::vector<Eigen::Vector3d> &vertices)
145  : Geometry3D(type), vertices_(vertices) {}
146 
147 public:
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:45
A bounding box that is aligned along the coordinate axes and defined by the min_bound and max_bound.
Definition: BoundingVolume.h:160
The base geometry class for 3D geometries.
Definition: Geometry3D.h:28
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:56
The base geometry class.
Definition: Geometry.h:18
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:23
MeshBash Class.
Definition: MeshBase.h:32
std::vector< Eigen::Vector3d > vertices_
Vertex coordinates.
Definition: MeshBase.h:149
MeshBase(Geometry::GeometryType type)
Definition: MeshBase.h:142
virtual bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: MeshBase.cpp:33
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: MeshBase.cpp:39
virtual OrientedBoundingBox GetMinimalOrientedBoundingBox(bool robust=false) const override
Definition: MeshBase.cpp:53
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:74
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:81
virtual MeshBase & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: MeshBase.cpp:57
DeformAsRigidAsPossibleEnergy
Definition: MeshBase.h:57
~MeshBase() override
Definition: MeshBase.h:61
MeshBase & PaintUniformColor(const Eigen::Vector3d &color)
Assigns each vertex in the TriangleMesh the same color.
Definition: MeshBase.h:131
bool HasVertexColors() const
Returns True if the mesh contains vertex colors.
Definition: MeshBase.h:112
MeshBase()
Default Constructor.
Definition: MeshBase.h:60
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Definition: MeshBase.cpp:45
SimplificationContraction
Indicates the method that is used for mesh simplification if multiple vertices are combined to a sing...
Definition: MeshBase.h:42
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:111
virtual MeshBase & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: MeshBase.cpp:63
MeshBase & NormalizeNormals()
Normalize vertex normals to length 1.
Definition: MeshBase.h:118
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:26
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: MeshBase.cpp:43
MeshBase operator+(const MeshBase &mesh) const
Definition: MeshBase.cpp:106
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:69
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:35
virtual OrientedBoundingBox GetOrientedBoundingBox(bool robust=false) const override
Definition: MeshBase.cpp:49
FilterScope
Indicates the scope of filter operations.
Definition: MeshBase.h:51
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:25
Definition: TriangleMeshSimplification.cpp:22
char type
Definition: FilePCD.cpp:41
Definition: PinholeCameraIntrinsic.cpp:16