Open3D (C++ API)
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 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 
37 #include "Open3D/Utility/Helper.h"
38 
39 namespace open3d {
40 namespace geometry {
41 
42 class PointCloud;
43 class TriangleMesh;
44 
45 class MeshBase : public Geometry3D {
46 public:
55 
62  enum class FilterScope { All, Color, Normal, Vertex };
63 
65  ~MeshBase() override {}
66 
67 public:
68  virtual MeshBase &Clear() override;
69  virtual bool IsEmpty() const override;
70  virtual Eigen::Vector3d GetMinBound() const override;
71  virtual Eigen::Vector3d GetMaxBound() const override;
72  virtual Eigen::Vector3d GetCenter() const override;
73  virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override;
74  virtual OrientedBoundingBox GetOrientedBoundingBox() const override;
75  virtual MeshBase &Transform(const Eigen::Matrix4d &transformation) override;
76  virtual MeshBase &Translate(const Eigen::Vector3d &translation,
77  bool relative = true) override;
78  virtual MeshBase &Scale(const double scale, bool center = true) override;
79  virtual MeshBase &Rotate(const Eigen::Matrix3d &R,
80  bool center = true) override;
81 
82  MeshBase &operator+=(const MeshBase &mesh);
83  MeshBase operator+(const MeshBase &mesh) const;
84 
85  bool HasVertices() const { return vertices_.size() > 0; }
86 
87  bool HasVertexNormals() const {
88  return vertices_.size() > 0 &&
89  vertex_normals_.size() == vertices_.size();
90  }
91 
92  bool HasVertexColors() const {
93  return vertices_.size() > 0 &&
94  vertex_colors_.size() == vertices_.size();
95  }
96 
98  for (size_t i = 0; i < vertex_normals_.size(); i++) {
99  vertex_normals_[i].normalize();
100  if (std::isnan(vertex_normals_[i](0))) {
101  vertex_normals_[i] = Eigen::Vector3d(0.0, 0.0, 1.0);
102  }
103  }
104  return *this;
105  }
106 
108  MeshBase &PaintUniformColor(const Eigen::Vector3d &color) {
110  return *this;
111  }
112 
114  std::tuple<std::shared_ptr<TriangleMesh>, std::vector<size_t>>
115  ComputeConvexHull() const;
116 
117 protected:
118  // Forward child class type to avoid indirect nonvirtual base
121  const std::vector<Eigen::Vector3d> &vertices)
122  : Geometry3D(type), vertices_(vertices) {}
123 
124 public:
125  std::vector<Eigen::Vector3d> vertices_;
126  std::vector<Eigen::Vector3d> vertex_normals_;
127  std::vector<Eigen::Vector3d> vertex_colors_;
128 };
129 
130 } // namespace geometry
131 } // namespace open3d
MeshBase & operator+=(const MeshBase &mesh)
Definition: MeshBase.cpp:96
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
Definition: MeshBase.cpp:65
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: MeshBase.cpp:63
The base geometry class.
Definition: Geometry.h:35
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:130
MeshBase()
Definition: MeshBase.h:64
MeshBase & PaintUniformColor(const Eigen::Vector3d &color)
Assigns each vertex in the TriangleMesh the same color.
Definition: MeshBase.h:108
Definition: MeshBase.h:45
MeshBase & NormalizeNormals()
Definition: MeshBase.h:97
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:44
Definition: TriangleMeshSimplification.cpp:42
virtual MeshBase & Rotate(const Eigen::Matrix3d &R, bool center=true) override
Apply rotation to the geometry coordinates and normals.
Definition: MeshBase.cpp:90
bool HasVertexNormals() const
Definition: MeshBase.h:87
virtual MeshBase & Scale(const double scale, bool center=true) override
Apply scaling to the geometry coordinates.
Definition: MeshBase.cpp:85
bool HasVertices() const
Definition: MeshBase.h:85
std::vector< Eigen::Vector3d > vertex_normals_
Definition: MeshBase.h:126
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: MeshBase.cpp:59
The base geometry class for 3D geometries.
Definition: Geometry3D.h:46
FilterScope
Definition: MeshBase.h:62
virtual MeshBase & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: MeshBase.cpp:73
virtual bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: MeshBase.cpp:53
SimplificationContraction
Definition: MeshBase.h:54
char type
Definition: FilePCD.cpp:57
std::vector< Eigen::Vector3d > vertex_colors_
Definition: MeshBase.h:127
MeshBase(Geometry::GeometryType type)
Definition: MeshBase.h:119
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
Definition: PinholeCameraIntrinsic.cpp:34
virtual OrientedBoundingBox GetOrientedBoundingBox() const override
Returns an oriented bounding box of the geometry.
Definition: MeshBase.cpp:69
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:40
MeshBase operator+(const MeshBase &mesh) const
Definition: MeshBase.cpp:121
MeshBase(Geometry::GeometryType type, const std::vector< Eigen::Vector3d > &vertices)
Definition: MeshBase.h:120
~MeshBase() override
Definition: MeshBase.h:65
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: MeshBase.cpp:55
std::vector< Eigen::Vector3d > vertices_
Definition: MeshBase.h:125
virtual MeshBase & Clear() override
Clear all elements in the geometry.
Definition: MeshBase.cpp:46
virtual MeshBase & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: MeshBase.cpp:79
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:71
bool HasVertexColors() const
Definition: MeshBase.h:92