ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvMeshBase.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.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 
17 // CV_CORE_LIB
18 #include <Eigen.h>
19 #include <GenericMesh.h>
20 #include <Helper.h>
21 
22 // LOCAL
23 #include "CV_db.h"
24 #include "ecvHObject.h"
25 
26 class ccMesh;
27 class ccBBox;
28 class ecvOrientedBBox;
29 class ccPointCloud;
30 
31 namespace cloudViewer {
32 namespace geometry {
33 
41  public ccHObject {
42 public:
44  ecvMeshBase(const char *name = "ecvMeshBase") : ccHObject(name) {}
45  ~ecvMeshBase() override {}
46 
47  // inherited methods (ccHObject)
48  inline virtual bool isSerializable() const override { return true; }
49  inline virtual CV_CLASS_ENUM getClassID() const override {
50  return CV_TYPES::MESH_BASE;
51  }
52  virtual ccBBox getOwnBB(bool withGLFeatures = false) override;
53  virtual void getBoundingBox(CCVector3 &bbMin, CCVector3 &bbMax) override;
54 
55  // inherited methods (GenericMesh)
56  inline virtual unsigned size() const override {
57  return static_cast<unsigned>(vertices_.size());
58  }
59  // inherited methods (GenericIndexedMesh)
60  virtual void placeIteratorAtBeginning() override {}
61  virtual void forEach(genericTriangleAction action) override {}
63  return nullptr;
64  }
65 
66 public:
67  virtual ecvMeshBase &clear();
68  virtual bool IsEmpty() const override;
69  virtual Eigen::Vector3d GetMinBound() const override;
70  virtual Eigen::Vector3d GetMaxBound() const override;
71  virtual Eigen::Vector3d GetCenter() const override;
72  virtual ccBBox GetAxisAlignedBoundingBox() const override;
73  virtual ecvOrientedBBox GetOrientedBoundingBox() const override;
75  const Eigen::Matrix4d &transformation) override;
76  virtual ecvMeshBase &Translate(const Eigen::Vector3d &translation,
77  bool relative = true) override;
78  virtual ecvMeshBase &Scale(const double s,
79  const Eigen::Vector3d &center) override;
80  virtual ecvMeshBase &Rotate(const Eigen::Matrix3d &R,
81  const Eigen::Vector3d &center) override;
82 
84  ecvMeshBase operator+(const ecvMeshBase &mesh) const;
85 
87  bool HasVertices() const { return vertices_.size() > 0; }
88 
90  bool HasVertexNormals() const {
91  return vertices_.size() > 0 &&
92  vertex_normals_.size() == vertices_.size();
93  }
94 
96  bool HasVertexColors() const {
97  return vertices_.size() > 0 &&
98  vertex_colors_.size() == vertices_.size();
99  }
100 
103  for (size_t i = 0; i < vertex_normals_.size(); i++) {
104  vertex_normals_[i].normalize();
105  if (std::isnan(vertex_normals_[i](0))) {
106  vertex_normals_[i] = Eigen::Vector3d(0.0, 0.0, 1.0);
107  }
108  }
109  return *this;
110  }
111 
115  ecvMeshBase &PaintUniformColor(const Eigen::Vector3d &color) {
116  ResizeAndPaintUniformColor(vertex_colors_, vertices_.size(), color);
117  return *this;
118  }
119 
121  std::tuple<std::shared_ptr<ccMesh>, std::vector<size_t>> ComputeConvexHull()
122  const;
123 
124 protected:
125  // Forward child class type to avoid indirect nonvirtual base
126  ecvMeshBase(const std::vector<Eigen::Vector3d> &vertices,
127  const char *name = "ecvMeshBase")
128  : ccHObject(name), vertices_(vertices) {}
129 
130 public:
132  std::vector<Eigen::Vector3d> vertices_;
134  std::vector<Eigen::Vector3d> vertex_normals_;
136  std::vector<Eigen::Vector3d> vertex_colors_;
137 };
138 
139 } // namespace geometry
140 } // namespace cloudViewer
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
Definition: CVTypes.h:97
#define CV_DB_LIB_API
Definition: CV_db.h:15
std::string name
math::float4 color
Bounding box structure.
Definition: ecvBBox.h:25
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
Triangular mesh.
Definition: ecvMesh.h:35
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
std::function< void(GenericTriangle &)> genericTriangleAction
Generic function to apply to a triangle (used by foreach)
Definition: GenericMesh.h:53
A generic triangle interface.
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
virtual void placeIteratorAtBeginning() override
Places the mesh iterator at the beginning.
Definition: ecvMeshBase.h:60
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
ecvMeshBase & PaintUniformColor(const Eigen::Vector3d &color)
Assigns each vertex in the TriangleMesh the same color.
Definition: ecvMeshBase.h:115
ecvMeshBase(const char *name="ecvMeshBase")
Default Constructor.
Definition: ecvMeshBase.h:44
virtual bool IsEmpty() const override
virtual ecvMeshBase & Scale(const double s, const Eigen::Vector3d &center) override
Apply scaling to the geometry coordinates. Given a scaling factor , and center , a given point is tr...
ecvMeshBase(const std::vector< Eigen::Vector3d > &vertices, const char *name="ecvMeshBase")
Definition: ecvMeshBase.h:126
virtual bool isSerializable() const override
Returns whether object is serializable of not.
Definition: ecvMeshBase.h:48
virtual unsigned size() const override
Returns the number of triangles.
Definition: ecvMeshBase.h:56
bool HasVertices() const
Returns True if the mesh contains vertices.
Definition: ecvMeshBase.h:87
virtual ecvMeshBase & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &center) override
Apply rotation to the geometry coordinates and normals. Given a rotation matrix , and center ,...
bool HasVertexColors() const
Returns True if the mesh contains vertex colors.
Definition: ecvMeshBase.h:96
virtual ecvMeshBase & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
std::tuple< std::shared_ptr< ccMesh >, std::vector< size_t > > ComputeConvexHull() const
Function that computes the convex hull of the triangle mesh using qhull.
virtual void getBoundingBox(CCVector3 &bbMin, CCVector3 &bbMax) override
Returns the mesh bounding-box.
virtual cloudViewer::GenericTriangle * _getNextTriangle() override
Returns the next triangle (relatively to the global iterator position)
Definition: ecvMeshBase.h:62
bool HasVertexNormals() const
Returns True if the mesh contains vertex normals.
Definition: ecvMeshBase.h:90
ecvMeshBase & NormalizeNormals()
Normalize vertex normals to length 1.
Definition: ecvMeshBase.h:102
virtual CV_CLASS_ENUM getClassID() const override
Returns class ID.
Definition: ecvMeshBase.h:49
virtual void forEach(genericTriangleAction action) override
Fast iteration mechanism.
Definition: ecvMeshBase.h:61
ecvMeshBase operator+(const ecvMeshBase &mesh) const
virtual ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
virtual ecvMeshBase & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
virtual ecvOrientedBBox GetOrientedBoundingBox() const override
virtual ecvMeshBase & clear()
std::vector< Eigen::Vector3d > vertex_normals_
Vertex normals.
Definition: ecvMeshBase.h:134
virtual ccBBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
std::vector< Eigen::Vector3d > vertices_
Vertex coordinates.
Definition: ecvMeshBase.h:132
std::vector< Eigen::Vector3d > vertex_colors_
RGB colors of vertices.
Definition: ecvMeshBase.h:136
ecvMeshBase & operator+=(const ecvMeshBase &mesh)
Helper functions for the ml ops.
@ MESH_BASE
Definition: CVTypes.h:148
Generic file read and write utility for python interface.