Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TriangleMesh.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 <numeric>
32 #include <tuple>
33 #include <unordered_map>
34 #include <unordered_set>
35 #include <vector>
36 
37 #include "open3d/geometry/Image.h"
39 #include "open3d/utility/Helper.h"
40 
41 namespace open3d {
42 namespace geometry {
43 
44 class PointCloud;
45 class TetraMesh;
46 
54 class TriangleMesh : public MeshBase {
55 public:
62  TriangleMesh(const std::vector<Eigen::Vector3d> &vertices,
63  const std::vector<Eigen::Vector3i> &triangles)
65  triangles_(triangles) {}
66  ~TriangleMesh() override {}
67 
68 public:
69  virtual TriangleMesh &Clear() override;
70  virtual TriangleMesh &Transform(
71  const Eigen::Matrix4d &transformation) override;
72  virtual TriangleMesh &Rotate(const Eigen::Matrix3d &R,
73  const Eigen::Vector3d &center) override;
74 
75 public:
76  TriangleMesh &operator+=(const TriangleMesh &mesh);
77  TriangleMesh operator+(const TriangleMesh &mesh) const;
78 
80  bool HasTriangles() const {
81  return vertices_.size() > 0 && triangles_.size() > 0;
82  }
83 
85  bool HasTriangleNormals() const {
86  return HasTriangles() && triangles_.size() == triangle_normals_.size();
87  }
88 
90  bool HasAdjacencyList() const {
91  return vertices_.size() > 0 &&
92  adjacency_list_.size() == vertices_.size();
93  }
94 
95  bool HasTriangleUvs() const {
96  return HasTriangles() && triangle_uvs_.size() == 3 * triangles_.size();
97  }
98 
100  bool HasTextures() const {
101  bool is_all_texture_valid = std::accumulate(
102  textures_.begin(), textures_.end(), true,
103  [](bool a, const Image &b) { return a && !b.IsEmpty(); });
104  return !textures_.empty() && is_all_texture_valid;
105  }
106 
107  bool HasMaterials() const { return !materials_.empty(); }
108 
109  bool HasTriangleMaterialIds() const {
110  return HasTriangles() &&
111  triangle_material_ids_.size() == triangles_.size();
112  }
113 
117  for (size_t i = 0; i < triangle_normals_.size(); i++) {
118  triangle_normals_[i].normalize();
119  if (std::isnan(triangle_normals_[i](0))) {
120  triangle_normals_[i] = Eigen::Vector3d(0.0, 0.0, 1.0);
121  }
122  }
123  return *this;
124  }
125 
128  TriangleMesh &ComputeTriangleNormals(bool normalized = true);
129 
132  TriangleMesh &ComputeVertexNormals(bool normalized = true);
133 
137 
141 
146 
150 
156 
162 
169  TriangleMesh &MergeCloseVertices(double eps);
170 
180  std::shared_ptr<TriangleMesh> FilterSharpen(
181  int number_of_iterations,
182  double strength,
183  FilterScope scope = FilterScope::All) const;
184 
193  std::shared_ptr<TriangleMesh> FilterSmoothSimple(
194  int number_of_iterations,
195  FilterScope scope = FilterScope::All) const;
196 
208  std::shared_ptr<TriangleMesh> FilterSmoothLaplacian(
209  int number_of_iterations,
210  double lambda,
211  FilterScope scope = FilterScope::All) const;
212 
223  std::shared_ptr<TriangleMesh> FilterSmoothTaubin(
224  int number_of_iterations,
225  double lambda = 0.5,
226  double mu = -0.53,
227  FilterScope scope = FilterScope::All) const;
228 
232  int EulerPoincareCharacteristic() const;
233 
237  std::vector<Eigen::Vector2i> GetNonManifoldEdges(
238  bool allow_boundary_edges = true) const;
239 
244  bool IsEdgeManifold(bool allow_boundary_edges = true) const;
245 
249  std::vector<int> GetNonManifoldVertices() const;
250 
254  bool IsVertexManifold() const;
255 
258  std::vector<Eigen::Vector2i> GetSelfIntersectingTriangles() const;
259 
262  bool IsSelfIntersecting() const;
263 
266  bool IsBoundingBoxIntersecting(const TriangleMesh &other) const;
267 
270  bool IsIntersecting(const TriangleMesh &other) const;
271 
275  bool IsOrientable() const;
276 
280  bool IsWatertight() const;
281 
285  bool OrientTriangles();
286 
289  std::unordered_map<Eigen::Vector2i,
290  std::vector<int>,
292  GetEdgeToTrianglesMap() const;
293 
296  std::unordered_map<Eigen::Vector2i,
297  std::vector<int>,
299  GetEdgeToVerticesMap() const;
300 
302  static double ComputeTriangleArea(const Eigen::Vector3d &p0,
303  const Eigen::Vector3d &p1,
304  const Eigen::Vector3d &p2);
305 
308  double GetTriangleArea(size_t triangle_idx) const;
309 
310  static inline Eigen::Vector3i GetOrderedTriangle(int vidx0,
311  int vidx1,
312  int vidx2) {
313  if (vidx0 > vidx2) {
314  std::swap(vidx0, vidx2);
315  }
316  if (vidx0 > vidx1) {
317  std::swap(vidx0, vidx1);
318  }
319  if (vidx1 > vidx2) {
320  std::swap(vidx1, vidx2);
321  }
322  return Eigen::Vector3i(vidx0, vidx1, vidx2);
323  }
324 
327  double GetSurfaceArea() const;
328 
331  double GetSurfaceArea(std::vector<double> &triangle_areas) const;
332 
337  double GetVolume() const;
338 
342  static Eigen::Vector4d ComputeTrianglePlane(const Eigen::Vector3d &p0,
343  const Eigen::Vector3d &p1,
344  const Eigen::Vector3d &p2);
345 
348  Eigen::Vector4d GetTrianglePlane(size_t triangle_idx) const;
349 
351  static inline Eigen::Vector2i GetOrderedEdge(int vidx0, int vidx1) {
352  return Eigen::Vector2i(std::min(vidx0, vidx1), std::max(vidx0, vidx1));
353  }
354 
357  std::shared_ptr<PointCloud> SamplePointsUniformlyImpl(
358  size_t number_of_points,
359  std::vector<double> &triangle_areas,
360  double surface_area,
361  bool use_triangle_normal,
362  int seed);
363 
370  std::shared_ptr<PointCloud> SamplePointsUniformly(
371  size_t number_of_points,
372  bool use_triangle_normal = false,
373  int seed = -1);
374 
386  std::shared_ptr<PointCloud> SamplePointsPoissonDisk(
387  size_t number_of_points,
388  double init_factor = 5,
389  const std::shared_ptr<PointCloud> pcl_init = nullptr,
390  bool use_triangle_normal = false,
391  int seed = -1);
392 
398  std::shared_ptr<TriangleMesh> SubdivideMidpoint(
399  int number_of_iterations) const;
400 
406  std::shared_ptr<TriangleMesh> SubdivideLoop(int number_of_iterations) const;
407 
414  std::shared_ptr<TriangleMesh> SimplifyVertexClustering(
415  double voxel_size,
416  SimplificationContraction contraction =
418 
428  std::shared_ptr<TriangleMesh> SimplifyQuadricDecimation(
429  int target_number_of_triangles,
430  double maximum_error,
431  double boundary_weight) const;
432 
442  std::shared_ptr<TriangleMesh> SelectByIndex(
443  const std::vector<size_t> &indices, bool cleanup = true) const;
444 
449  std::shared_ptr<TriangleMesh> Crop(
450  const AxisAlignedBoundingBox &bbox) const;
451 
456  std::shared_ptr<TriangleMesh> Crop(const OrientedBoundingBox &bbox) const;
457 
464  std::tuple<std::vector<int>, std::vector<size_t>, std::vector<double>>
466 
473  void RemoveTrianglesByIndex(const std::vector<size_t> &triangle_indices);
474 
481  void RemoveTrianglesByMask(const std::vector<bool> &triangle_mask);
482 
489  void RemoveVerticesByIndex(const std::vector<size_t> &vertex_indices);
490 
497  void RemoveVerticesByMask(const std::vector<bool> &vertex_mask);
498 
512  std::shared_ptr<TriangleMesh> DeformAsRigidAsPossible(
513  const std::vector<int> &constraint_vertex_indices,
514  const std::vector<Eigen::Vector3d> &constraint_vertex_positions,
515  size_t max_iter,
518  double smoothed_alpha = 0.01) const;
519 
531  static std::shared_ptr<TriangleMesh> CreateFromPointCloudAlphaShape(
532  const PointCloud &pcd,
533  double alpha,
534  std::shared_ptr<TetraMesh> tetra_mesh = nullptr,
535  std::vector<size_t> *pt_map = nullptr);
536 
550  static std::shared_ptr<TriangleMesh> CreateFromPointCloudBallPivoting(
551  const PointCloud &pcd, const std::vector<double> &radii);
552 
576  static std::tuple<std::shared_ptr<TriangleMesh>, std::vector<double>>
578  size_t depth = 8,
579  size_t width = 0,
580  float scale = 1.1f,
581  bool linear_fit = false,
582  int n_threads = -1);
583 
589  static std::shared_ptr<TriangleMesh> CreateTetrahedron(
590  double radius = 1.0, bool create_uv_map = false);
591 
597  static std::shared_ptr<TriangleMesh> CreateOctahedron(
598  double radius = 1.0, bool create_uv_map = false);
599 
604  static std::shared_ptr<TriangleMesh> CreateIcosahedron(
605  double radius = 1.0, bool create_uv_map = false);
606 
615  static std::shared_ptr<TriangleMesh> CreateBox(
616  double width = 1.0,
617  double height = 1.0,
618  double depth = 1.0,
619  bool create_uv_map = false,
620  bool map_texture_to_each_face = false);
621 
632  static std::shared_ptr<TriangleMesh> CreateSphere(
633  double radius = 1.0,
634  int resolution = 20,
635  bool create_uv_map = false);
636 
648  static std::shared_ptr<TriangleMesh> CreateCylinder(
649  double radius = 1.0,
650  double height = 2.0,
651  int resolution = 20,
652  int split = 4,
653  bool create_uv_map = false);
654 
665  static std::shared_ptr<TriangleMesh> CreateCone(double radius = 1.0,
666  double height = 2.0,
667  int resolution = 20,
668  int split = 1,
669  bool create_uv_map = false);
670 
681  static std::shared_ptr<TriangleMesh> CreateTorus(
682  double torus_radius = 1.0,
683  double tube_radius = 0.5,
684  int radial_resolution = 30,
685  int tubular_resolution = 20);
686 
707  static std::shared_ptr<TriangleMesh> CreateArrow(
708  double cylinder_radius = 1.0,
709  double cone_radius = 1.5,
710  double cylinder_height = 5.0,
711  double cone_height = 4.0,
712  int resolution = 20,
713  int cylinder_split = 4,
714  int cone_split = 1);
715 
721  static std::shared_ptr<TriangleMesh> CreateCoordinateFrame(
722  double size = 1.0,
723  const Eigen::Vector3d &origin = Eigen::Vector3d(0.0, 0.0, 0.0));
724 
735  static std::shared_ptr<TriangleMesh> CreateMoebius(int length_split = 70,
736  int width_split = 15,
737  int twists = 1,
738  double radius = 1,
739  double flatness = 1,
740  double width = 1,
741  double scale = 1);
742 
743 protected:
744  // Forward child class type to avoid indirect nonvirtual base
746 
748  std::shared_ptr<TriangleMesh> &mesh,
749  const std::vector<Eigen::Vector3d> &prev_vertices,
750  const std::vector<Eigen::Vector3d> &prev_vertex_normals,
751  const std::vector<Eigen::Vector3d> &prev_vertex_colors,
752  const std::vector<std::unordered_set<int>> &adjacency_list,
753  double lambda,
754  bool filter_vertex,
755  bool filter_normal,
756  bool filter_color) const;
757 
766  std::unordered_map<Eigen::Vector2i,
767  double,
770  const std::unordered_map<Eigen::Vector2i,
771  std::vector<int>,
773  &edges_to_vertices,
774  double min_weight = std::numeric_limits<double>::lowest()) const;
775 
776 public:
778  std::vector<Eigen::Vector3i> triangles_;
780  std::vector<Eigen::Vector3d> triangle_normals_;
783  std::vector<std::unordered_set<int>> adjacency_list_;
785  std::vector<Eigen::Vector2d> triangle_uvs_;
786 
787  struct Material {
789  float f4[4] = {0};
790 
792  f4[0] = 0;
793  f4[1] = 0;
794  f4[2] = 0;
795  f4[3] = 0;
796  }
797 
798  MaterialParameter(const float v1,
799  const float v2,
800  const float v3,
801  const float v4) {
802  f4[0] = v1;
803  f4[1] = v2;
804  f4[2] = v3;
805  f4[3] = v4;
806  }
807 
808  MaterialParameter(const float v1, const float v2, const float v3) {
809  f4[0] = v1;
810  f4[1] = v2;
811  f4[2] = v3;
812  f4[3] = 1;
813  }
814 
815  MaterialParameter(const float v1, const float v2) {
816  f4[0] = v1;
817  f4[1] = v2;
818  f4[2] = 0;
819  f4[3] = 0;
820  }
821 
822  explicit MaterialParameter(const float v1) {
823  f4[0] = v1;
824  f4[1] = 0;
825  f4[2] = 0;
826  f4[3] = 0;
827  }
828 
829  static MaterialParameter CreateRGB(const float r,
830  const float g,
831  const float b) {
832  return {r, g, b, 1.f};
833  }
834 
835  float r() const { return f4[0]; }
836  float g() const { return f4[1]; }
837  float b() const { return f4[2]; }
838  float a() const { return f4[3]; }
839  };
840 
842  float baseMetallic = 0.f;
843  float baseRoughness = 1.f;
844  float baseReflectance = 0.5f;
845  float baseClearCoat = 0.f;
847  float baseAnisotropy = 0.f;
848 
849  std::shared_ptr<Image> albedo;
850  std::shared_ptr<Image> normalMap;
851  std::shared_ptr<Image> ambientOcclusion;
852  std::shared_ptr<Image> metallic;
853  std::shared_ptr<Image> roughness;
854  std::shared_ptr<Image> reflectance;
855  std::shared_ptr<Image> clearCoat;
856  std::shared_ptr<Image> clearCoatRoughness;
857  std::shared_ptr<Image> anisotropy;
858 
859  std::unordered_map<std::string, MaterialParameter> floatParameters;
860  std::unordered_map<std::string, Image> additionalMaps;
861  };
862 
863  std::unordered_map<std::string, Material> materials_;
864 
866  std::vector<int> triangle_material_ids_;
868  std::vector<Image> textures_;
869 };
870 
871 } // namespace geometry
872 } // namespace open3d
std::shared_ptr< Image > anisotropy
Definition: TriangleMesh.h:857
float baseRoughness
Definition: TriangleMesh.h:843
static std::shared_ptr< TriangleMesh > CreateFromPointCloudBallPivoting(const PointCloud &pcd, const std::vector< double > &radii)
Definition: SurfaceReconstructionBallPivoting.cpp:749
bool HasTriangleMaterialIds() const
Definition: TriangleMesh.h:109
bool IsSelfIntersecting() const
Definition: TriangleMesh.cpp:1397
std::shared_ptr< PointCloud > SamplePointsUniformlyImpl(size_t number_of_points, std::vector< double > &triangle_areas, double surface_area, bool use_triangle_normal, int seed)
Definition: TriangleMesh.cpp:450
std::vector< Eigen::Vector3i > triangles_
List of triangles denoted by the index of points forming the triangle.
Definition: TriangleMesh.h:778
bool HasMaterials() const
Definition: TriangleMesh.h:107
TriangleMesh & RemoveDuplicatedTriangles()
Function that removes duplicated triangles, i.e., removes triangles that reference the same three ver...
Definition: TriangleMesh.cpp:727
bool IsOrientable() const
Definition: TriangleMesh.cpp:1115
void RemoveVerticesByIndex(const std::vector< size_t > &vertex_indices)
This function removes the vertices with index in vertex_indices. Note that also all triangles associa...
Definition: TriangleMesh.cpp:1534
void RemoveVerticesByMask(const std::vector< bool > &vertex_mask)
This function removes the vertices that are masked in vertex_mask. Note that also all triangles assoc...
Definition: TriangleMesh.cpp:1551
float baseClearCoatRoughness
Definition: TriangleMesh.h:846
std::shared_ptr< TriangleMesh > SubdivideLoop(int number_of_iterations) const
Definition: TriangleMeshSubdivide.cpp:115
MaterialParameter baseColor
Definition: TriangleMesh.h:841
float baseClearCoat
Definition: TriangleMesh.h:845
The base geometry class.
Definition: Geometry.h:37
std::vector< int > GetNonManifoldVertices() const
Definition: TriangleMesh.cpp:1305
MaterialParameter(const float v1, const float v2, const float v3, const float v4)
Definition: TriangleMesh.h:798
std::shared_ptr< TriangleMesh > FilterSmoothSimple(int number_of_iterations, FilterScope scope=FilterScope::All) const
Function to smooth triangle mesh with simple neighbour average.
Definition: TriangleMesh.cpp:247
TriangleMesh & MergeCloseVertices(double eps)
Function that will merge close by vertices to a single one. The vertex position, normal and color wil...
Definition: TriangleMesh.cpp:932
std::shared_ptr< TriangleMesh > SelectByIndex(const std::vector< size_t > &indices, bool cleanup=true) const
Definition: TriangleMesh.cpp:1595
static std::shared_ptr< TriangleMesh > CreateMoebius(int length_split=70, int width_split=15, int twists=1, double radius=1, double flatness=1, double width=1, double scale=1)
Definition: TriangleMeshFactory.cpp:806
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:150
std::shared_ptr< Image > roughness
Definition: TriangleMesh.h:853
std::unordered_map< Eigen::Vector2i, std::vector< int >, utility::hash_eigen< Eigen::Vector2i > > GetEdgeToVerticesMap() const
Definition: TriangleMesh.cpp:1153
bool HasTextures() const
Returns true if the mesh has texture.
Definition: TriangleMesh.h:100
std::shared_ptr< Image > normalMap
Definition: TriangleMesh.h:850
bool IsBoundingBoxIntersecting(const TriangleMesh &other) const
Definition: TriangleMesh.cpp:1401
static std::shared_ptr< TriangleMesh > CreateIcosahedron(double radius=1.0, bool create_uv_map=false)
Definition: TriangleMeshFactory.cpp:103
TriangleMesh()
Default Constructor.
Definition: TriangleMesh.h:57
static std::shared_ptr< TriangleMesh > CreateTetrahedron(double radius=1.0, bool create_uv_map=false)
Definition: TriangleMeshFactory.cpp:33
Definition: TriangleMesh.h:787
void RemoveTrianglesByIndex(const std::vector< size_t > &triangle_indices)
This function removes the triangles with index in triangle_indices. Call RemoveUnreferencedVertices t...
Definition: TriangleMesh.cpp:1494
std::shared_ptr< TriangleMesh > FilterSharpen(int number_of_iterations, double strength, FilterScope scope=FilterScope::All) const
Function to sharpen triangle mesh.
Definition: TriangleMesh.cpp:176
MeshBash Class.
Definition: MeshBase.h:51
MeshBase & NormalizeNormals()
Normalize vertex normals to length 1.
Definition: MeshBase.h:117
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:44
std::unordered_map< std::string, MaterialParameter > floatParameters
Definition: TriangleMesh.h:859
A point cloud consists of point coordinates, and optionally point colors and point normals...
Definition: PointCloud.h:54
bool IsEdgeManifold(bool allow_boundary_edges=true) const
Definition: TriangleMesh.cpp:1292
float b() const
Definition: TriangleMesh.h:837
TriangleMesh & ComputeVertexNormals(bool normalized=true)
Function to compute vertex normals, usually called before rendering.
Definition: TriangleMesh.cpp:145
bool HasTriangleUvs() const
Definition: TriangleMesh.h:95
static double ComputeTriangleArea(const Eigen::Vector3d &p0, const Eigen::Vector3d &p1, const Eigen::Vector3d &p2)
Function that computes the area of a mesh triangle.
Definition: TriangleMesh.cpp:1169
std::unordered_map< Eigen::Vector2i, std::vector< int >, utility::hash_eigen< Eigen::Vector2i > > GetEdgeToTrianglesMap() const
Definition: TriangleMesh.cpp:1134
static Eigen::Vector2i GetOrderedEdge(int vidx0, int vidx1)
Helper function to get an edge with ordered vertex indices.
Definition: TriangleMesh.h:351
Eigen::Vector4d GetTrianglePlane(size_t triangle_idx) const
Definition: TriangleMesh.cpp:1255
std::tuple< std::vector< int >, std::vector< size_t >, std::vector< double > > ClusterConnectedTriangles() const
Function that clusters connected triangles, i.e., triangles that are connected via edges are assigned...
Definition: TriangleMesh.cpp:1429
static std::shared_ptr< TriangleMesh > CreateCoordinateFrame(double size=1.0, const Eigen::Vector3d &origin=Eigen::Vector3d(0.0, 0.0, 0.0))
Definition: TriangleMeshFactory.cpp:767
std::vector< Eigen::Vector2i > GetSelfIntersectingTriangles() const
Definition: TriangleMesh.cpp:1365
TriangleMesh & operator+=(const TriangleMesh &mesh)
Definition: TriangleMesh.cpp:71
std::shared_ptr< TriangleMesh > FilterSmoothLaplacian(int number_of_iterations, double lambda, FilterScope scope=FilterScope::All) const
Function to smooth triangle mesh using Laplacian.
Definition: TriangleMesh.cpp:363
float g() const
Definition: TriangleMesh.h:836
int size
Definition: FilePCD.cpp:59
TriangleMesh & RemoveDegenerateTriangles()
Function that removes degenerate triangles, i.e., triangles that reference a single vertex multiple t...
Definition: TriangleMesh.cpp:822
std::unordered_map< std::string, Material > materials_
Definition: TriangleMesh.h:863
std::shared_ptr< TriangleMesh > Crop(const AxisAlignedBoundingBox &bbox) const
Definition: TriangleMesh.cpp:1655
bool IsVertexManifold() const
Definition: TriangleMesh.cpp:1361
Definition: Helper.h:86
bool IsIntersecting(const TriangleMesh &other) const
Definition: TriangleMesh.cpp:1406
TriangleMesh & ComputeAdjacencyList()
Function to compute adjacency list, call before adjacency list is needed.
Definition: TriangleMesh.cpp:162
static std::shared_ptr< TriangleMesh > CreateBox(double width=1.0, double height=1.0, double depth=1.0, bool create_uv_map=false, bool map_texture_to_each_face=false)
Definition: TriangleMeshFactory.cpp:160
bool IsWatertight() const
Definition: TriangleMesh.cpp:1120
std::shared_ptr< TriangleMesh > DeformAsRigidAsPossible(const std::vector< int > &constraint_vertex_indices, const std::vector< Eigen::Vector3d > &constraint_vertex_positions, size_t max_iter, DeformAsRigidAsPossibleEnergy energy=DeformAsRigidAsPossibleEnergy::Spokes, double smoothed_alpha=0.01) const
This function deforms the mesh using the method by Sorkine and Alexa, "As-Rigid-As-Possible Surface M...
Definition: TriangleMeshDeformation.cpp:37
TriangleMesh & NormalizeNormals()
Normalize both triangle normals and vertex normals to length 1.
Definition: TriangleMesh.h:115
TriangleMesh(const std::vector< Eigen::Vector3d > &vertices, const std::vector< Eigen::Vector3i > &triangles)
Parameterized Constructor.
Definition: TriangleMesh.h:62
virtual TriangleMesh & 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: TriangleMesh.cpp:64
static std::shared_ptr< TriangleMesh > CreateCylinder(double radius=1.0, double height=2.0, int resolution=20, int split=4, bool create_uv_map=false)
Definition: TriangleMeshFactory.cpp:389
void swap(optional< T > &x, optional< T > &y) noexcept(noexcept(x.swap(y)))
Definition: Optional.h:895
virtual TriangleMesh & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: TriangleMesh.cpp:58
static std::tuple< std::shared_ptr< TriangleMesh >, std::vector< double > > CreateFromPointCloudPoisson(const PointCloud &pcd, size_t depth=8, size_t width=0, float scale=1.1f, bool linear_fit=false, int n_threads=-1)
Function that computes a triangle mesh from an oriented PointCloud pcd. This implements the Screened ...
Definition: SurfaceReconstructionPoisson.cpp:740
FilterScope
Indicates the scope of filter operations.
Definition: MeshBase.h:70
SimplificationContraction
Indicates the method that is used for mesh simplification if multiple vertices are combined to a sing...
Definition: MeshBase.h:61
DeformAsRigidAsPossibleEnergy
Definition: MeshBase.h:76
virtual TriangleMesh & Clear() override
Clear all elements in the geometry.
Definition: TriangleMesh.cpp:45
std::vector< Image > textures_
Textures of the image.
Definition: TriangleMesh.h:868
std::shared_ptr< Image > albedo
Definition: TriangleMesh.h:849
void RemoveTrianglesByMask(const std::vector< bool > &triangle_mask)
This function removes the triangles that are masked in triangle_mask. Call RemoveUnreferencedVertices...
Definition: TriangleMesh.cpp:1511
bool HasTriangles() const
Returns true if the mesh contains triangles.
Definition: TriangleMesh.h:80
TriangleMesh operator+(const TriangleMesh &mesh) const
Definition: TriangleMesh.cpp:126
static Eigen::Vector4d ComputeTrianglePlane(const Eigen::Vector3d &p0, const Eigen::Vector3d &p1, const Eigen::Vector3d &p2)
Definition: TriangleMesh.cpp:1239
std::shared_ptr< Image > clearCoat
Definition: TriangleMesh.h:855
bool OrientTriangles()
Definition: TriangleMesh.cpp:1124
TriangleMesh & RemoveNonManifoldEdges()
Function that removes all non-manifold edges, by successively deleting triangles with the smallest su...
Definition: TriangleMesh.cpp:852
static std::shared_ptr< TriangleMesh > CreateTorus(double torus_radius=1.0, double tube_radius=0.5, int radial_resolution=30, int tubular_resolution=20)
Definition: TriangleMeshFactory.cpp:672
float r() const
Definition: TriangleMesh.h:835
char type
Definition: FilePCD.cpp:60
std::shared_ptr< TriangleMesh > SubdivideMidpoint(int number_of_iterations) const
Definition: TriangleMeshSubdivide.cpp:37
static std::shared_ptr< TriangleMesh > CreateFromPointCloudAlphaShape(const PointCloud &pcd, double alpha, std::shared_ptr< TetraMesh > tetra_mesh=nullptr, std::vector< size_t > *pt_map=nullptr)
Alpha shapes are a generalization of the convex hull. With decreasing alpha value the shape schrinks ...
Definition: SurfaceReconstructionAlphaShape.cpp:40
void FilterSmoothLaplacianHelper(std::shared_ptr< TriangleMesh > &mesh, const std::vector< Eigen::Vector3d > &prev_vertices, const std::vector< Eigen::Vector3d > &prev_vertex_normals, const std::vector< Eigen::Vector3d > &prev_vertex_colors, const std::vector< std::unordered_set< int >> &adjacency_list, double lambda, bool filter_vertex, bool filter_normal, bool filter_color) const
Definition: TriangleMesh.cpp:313
static std::shared_ptr< TriangleMesh > CreateArrow(double cylinder_radius=1.0, double cone_radius=1.5, double cylinder_height=5.0, double cone_height=4.0, int resolution=20, int cylinder_split=4, int cone_split=1)
Definition: TriangleMeshFactory.cpp:724
bool HasAdjacencyList() const
Returns true if the mesh contains adjacency normals.
Definition: TriangleMesh.h:90
std::shared_ptr< Image > ambientOcclusion
Definition: TriangleMesh.h:851
Definition: PinholeCameraIntrinsic.cpp:35
double GetTriangleArea(size_t triangle_idx) const
Definition: TriangleMesh.cpp:1178
std::vector< Eigen::Vector2i > GetNonManifoldEdges(bool allow_boundary_edges=true) const
Definition: TriangleMesh.cpp:1278
std::shared_ptr< Image > reflectance
Definition: TriangleMesh.h:854
std::shared_ptr< PointCloud > SamplePointsUniformly(size_t number_of_points, bool use_triangle_normal=false, int seed=-1)
Definition: TriangleMesh.cpp:518
static std::shared_ptr< TriangleMesh > CreateCone(double radius=1.0, double height=2.0, int resolution=20, int split=1, bool create_uv_map=false)
Definition: TriangleMeshFactory.cpp:545
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:42
~TriangleMesh() override
Definition: TriangleMesh.h:66
std::shared_ptr< PointCloud > SamplePointsPoissonDisk(size_t number_of_points, double init_factor=5, const std::shared_ptr< PointCloud > pcl_init=nullptr, bool use_triangle_normal=false, int seed=-1)
Definition: TriangleMesh.cpp:538
std::unordered_map< std::string, Image > additionalMaps
Definition: TriangleMesh.h:860
int height
Definition: FilePCD.cpp:72
std::shared_ptr< TriangleMesh > SimplifyQuadricDecimation(int target_number_of_triangles, double maximum_error, double boundary_weight) const
Definition: TriangleMeshSimplification.cpp:265
int EulerPoincareCharacteristic() const
Definition: TriangleMesh.cpp:1263
std::vector< std::unordered_set< int > > adjacency_list_
Definition: TriangleMesh.h:783
std::vector< Eigen::Vector3d > triangle_normals_
Triangle normals.
Definition: TriangleMesh.h:780
MaterialParameter(const float v1, const float v2)
Definition: TriangleMesh.h:815
TriangleMesh(Geometry::GeometryType type)
Definition: TriangleMesh.h:745
TriangleMesh & RemoveUnreferencedVertices()
This function removes vertices from the triangle mesh that are not referenced in any triangle of the ...
Definition: TriangleMesh.cpp:779
bool HasTriangleNormals() const
Returns true if the mesh contains triangle normals.
Definition: TriangleMesh.h:85
std::vector< Eigen::Vector3d > vertices_
Vertex coordinates.
Definition: MeshBase.h:148
Triangle mesh contains vertices and triangles represented by the indices to the vertices.
Definition: TriangleMesh.h:54
MaterialParameter(const float v1)
Definition: TriangleMesh.h:822
TriangleMesh & ComputeTriangleNormals(bool normalized=true)
Function to compute triangle normals, usually called before rendering.
Definition: TriangleMesh.cpp:130
std::vector< int > triangle_material_ids_
List of material ids.
Definition: TriangleMesh.h:866
TriangleMesh & RemoveDuplicatedVertices()
Function that removes duplicated verties, i.e., vertices that have identical coordinates.
Definition: TriangleMesh.cpp:684
double GetSurfaceArea() const
Definition: TriangleMesh.cpp:1186
static MaterialParameter CreateRGB(const float r, const float g, const float b)
Definition: TriangleMesh.h:829
float baseMetallic
Definition: TriangleMesh.h:842
float baseReflectance
Definition: TriangleMesh.h:844
std::unordered_map< Eigen::Vector2i, double, utility::hash_eigen< Eigen::Vector2i > > ComputeEdgeWeightsCot(const std::unordered_map< Eigen::Vector2i, std::vector< int >, utility::hash_eigen< Eigen::Vector2i >> &edges_to_vertices, double min_weight=std::numeric_limits< double >::lowest()) const
Function that computes for each edge in the triangle mesh and passed as parameter edges_to_vertices t...
Definition: TriangleMesh.cpp:1679
static std::shared_ptr< TriangleMesh > CreateSphere(double radius=1.0, int resolution=20, bool create_uv_map=false)
Definition: TriangleMeshFactory.cpp:222
static Eigen::Vector3i GetOrderedTriangle(int vidx0, int vidx1, int vidx2)
Definition: TriangleMesh.h:310
double GetVolume() const
Definition: TriangleMesh.cpp:1206
float a() const
Definition: TriangleMesh.h:838
std::shared_ptr< Image > clearCoatRoughness
Definition: TriangleMesh.h:856
std::shared_ptr< TriangleMesh > SimplifyVertexClustering(double voxel_size, SimplificationContraction contraction=SimplificationContraction::Average) const
Definition: TriangleMeshSimplification.cpp:91
std::vector< Eigen::Vector2d > triangle_uvs_
List of uv coordinates per triangle.
Definition: TriangleMesh.h:785
The Image class stores image with customizable width, height, num of channels and bytes per channel...
Definition: Image.h:53
float baseAnisotropy
Definition: TriangleMesh.h:847
static std::shared_ptr< TriangleMesh > CreateOctahedron(double radius=1.0, bool create_uv_map=false)
Definition: TriangleMeshFactory.cpp:70
std::shared_ptr< TriangleMesh > FilterSmoothTaubin(int number_of_iterations, double lambda=0.5, double mu=-0.53, FilterScope scope=FilterScope::All) const
Function to smooth triangle mesh using method of Taubin, "Curve and Surface Smoothing Without Shrinka...
Definition: TriangleMesh.cpp:402
#define max(x, y)
Definition: SVD3x3CPU.h:38
MaterialParameter(const float v1, const float v2, const float v3)
Definition: TriangleMesh.h:808
std::shared_ptr< Image > metallic
Definition: TriangleMesh.h:852
int width
Definition: FilePCD.cpp:71