ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvMesh.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 // cloudViewer
11 #include <Helper.h>
12 #include <PointProjectionTools.h>
13 #include <SimpleTriangle.h>
14 
15 #include <Eigen/Core>
16 
17 // Local
18 #include <unordered_map>
19 #include <unordered_set>
20 
21 #include "Image.h"
22 #include "ecvGenericMesh.h"
23 
24 namespace cloudViewer {
25 namespace geometry {
26 class TetraMesh;
27 }
28 } // namespace cloudViewer
29 
30 class ccPolyline;
31 class ecvOrientedBBox;
32 class ecvProgressDialog;
33 
36 public:
38 
40  explicit ccMesh(ccGenericPointCloud* vertices = nullptr);
41 
42  ccMesh(const ccMesh& mesh);
43 
48  explicit ccMesh(const std::vector<Eigen::Vector3d>& vertices,
49  const std::vector<Eigen::Vector3i>& triangles);
50 
52 
57  ccGenericPointCloud* giVertices);
58 
60  ~ccMesh() override;
61 
63  CV_CLASS_ENUM getClassID() const override { return CV_TYPES::MESH; }
64 
67 
68  // Creates associated vertices cloud internally.
69  bool CreateInternalCloud();
70 
72 
78  ccMesh* cloneMesh(ccGenericPointCloud* vertices = nullptr,
79  ccMaterialSet* clonedMaterials = nullptr,
80  NormsIndexesTableType* clonedNormsTable = nullptr,
81  TextureCoordsContainer* cloneTexCoords = nullptr);
82 
84 
89  ccMesh* partialClone(const std::vector<unsigned>& triangleIndices,
90  int* warnings = nullptr) const;
91 
93  int vidx1,
94  int vidx2) {
95  if (vidx0 > vidx2) {
96  std::swap(vidx0, vidx2);
97  }
98  if (vidx0 > vidx1) {
99  std::swap(vidx0, vidx1);
100  }
101  if (vidx1 > vidx2) {
102  std::swap(vidx1, vidx2);
103  }
104  return cloudViewer::VerticesIndexes(static_cast<unsigned int>(vidx0),
105  static_cast<unsigned int>(vidx1),
106  static_cast<unsigned int>(vidx2));
107  }
108 
110 
114  bool updateNormals = false,
115  PointCoordinateType maxEdgeLength = 0,
116  unsigned char dim = 2);
117 
120  ccPolyline* p2,
121  CCVector3* projectionDir = nullptr);
122 
124 
128  bool merge(const ccMesh* mesh, bool createSubMesh);
129 
130  ccMesh& operator=(const ccMesh& mesh);
131  ccMesh& operator+=(const ccMesh& mesh);
132  ccMesh operator+(const ccMesh& mesh) const;
133 
134  void clear();
135 
136  // inherited methods (ccHObject)
137  unsigned getUniqueIDForDisplay() const override;
138  ccBBox getOwnBB(bool withGLFeatures = false) override;
139  bool isSerializable() const override { return true; }
140  const ccGLMatrix& getGLTransformationHistory() const override;
141 
142  // inherited methods (ccGenericMesh)
143  inline ccGenericPointCloud* getAssociatedCloud() const override {
144  return m_associatedCloud;
145  }
146  void refreshBB() override;
147  bool interpolateNormalsBC(unsigned triIndex,
148  const CCVector3d& w,
149  CCVector3& N) override;
150  bool interpolateColors(unsigned triIndex,
151  const CCVector3& P,
152  ecvColor::Rgb& C) override;
153  void computeInterpolationWeights(unsigned triIndex,
154  const CCVector3& P,
155  CCVector3d& weights) const override;
156  bool getColorFromMaterial(unsigned triIndex,
157  const CCVector3& P,
158  ecvColor::Rgb& C,
159  bool interpolateColorIfNoTexture) override;
160  bool getVertexColorFromMaterial(unsigned triIndex,
161  unsigned char vertIndex,
162  ecvColor::Rgb& C,
163  bool returnColorIfNoTexture) override;
164  unsigned capacity() const override;
165 
166  // inherited methods (GenericIndexedMesh)
167  void forEach(genericTriangleAction action) override;
168  void placeIteratorAtBeginning() override;
171  unsigned triangleIndex) override; // temporary
174  unsigned triangleIndex) override;
175  virtual void getTriangleVertices(unsigned triangleIndex,
176  CCVector3& A,
177  CCVector3& B,
178  CCVector3& C) const override;
179  virtual void getTriangleVertices(unsigned triangleIndex,
180  double A[3],
181  double B[3],
182  double C[3]) const override;
183 
184  unsigned int getVerticeSize() const;
185 
186  Eigen::Vector3d getVertice(size_t index) const;
187  void setVertice(size_t index, const Eigen::Vector3d& vertice);
188  void addVertice(const Eigen::Vector3d& vertice);
189  std::vector<Eigen::Vector3d> getEigenVertices() const;
190  void addEigenVertices(const std::vector<Eigen::Vector3d>& vertices);
191  void setEigenVertices(const std::vector<Eigen::Vector3d>& vertices);
192 
193  Eigen::Vector3d getVertexNormal(size_t index) const;
194  void setVertexNormal(size_t index, const Eigen::Vector3d& normal);
195  void addVertexNormal(const Eigen::Vector3d& normal);
196  std::vector<Eigen::Vector3d> getVertexNormals() const;
197  void addVertexNormals(const std::vector<Eigen::Vector3d>& normals);
198  void setVertexNormals(const std::vector<Eigen::Vector3d>& normals);
199 
200  Eigen::Vector3d getVertexColor(size_t index) const;
201  void setVertexColor(size_t index, const Eigen::Vector3d& color);
202  void addVertexColor(const Eigen::Vector3d& color);
203  std::vector<Eigen::Vector3d> getVertexColors() const;
205  void addVertexColors(const std::vector<Eigen::Vector3d>& colors);
206  void setVertexColors(const std::vector<Eigen::Vector3d>& colors);
207 
208  inline bool HasVertices() const { return getVerticeSize() != 0; }
209 
210  std::vector<CCVector3>& getVerticesPtr();
211  const std::vector<CCVector3>& getVertices() const;
212 
213  virtual unsigned size() const override;
214  void getBoundingBox(CCVector3& bbMin, CCVector3& bbMax) override;
215  bool normalsAvailable() const override { return hasNormals(); }
216  bool interpolateNormals(unsigned triIndex,
217  const CCVector3& P,
218  CCVector3& N) override;
219 
220  // const version of getTriangleVertIndexes
221  void getTriangleVertIndexes(size_t triangleIndex,
222  Eigen::Vector3i& vertIndx) const;
224  unsigned triangleIndex) const;
225 
226  // inherited methods (ccDrawableObject)
227  bool hasColors() const override;
228  bool hasNormals() const override;
229  bool HasVertexNormals() const;
230  bool hasScalarFields() const override;
231  bool hasDisplayedScalarField() const override;
232  bool normalsShown() const override;
234 
236 
239 
241 
243  void shiftTriangleIndexes(unsigned shift);
244 
246 
249 
251 
258  void addTriangle(unsigned i1, unsigned i2, unsigned i3);
260  inline void addTriangle(const Eigen::Vector3i& index) {
261  addTriangle(static_cast<unsigned>(index[0]),
262  static_cast<unsigned>(index[1]),
263  static_cast<unsigned>(index[2]));
264  }
265  inline void addTriangles(const std::vector<Eigen::Vector3i>& triangles) {
266  for (auto& tri : triangles) {
267  addTriangle(tri);
268  }
269  }
270 
271  void setTriangle(size_t index, const Eigen::Vector3i& triangle);
272  void setTriangles(const std::vector<Eigen::Vector3i>& triangles);
273  Eigen::Vector3i getTriangle(size_t index) const;
274  std::vector<Eigen::Vector3i> getTriangles() const;
275 
280  return m_triVertIndexes;
281  }
282 
284 
287  bool reserve(std::size_t n);
288  bool reserveAssociatedCloud(std::size_t n,
289  bool init_color = false,
290  bool init_normal = false);
291 
293 
298  bool resize(size_t n);
299  bool resizeAssociatedCloud(std::size_t n);
300 
302  inline void shrinkToFit() {
303  if (size() < capacity()) resize(size());
304  }
306 
307  /*********************************************************/
308  /************** PER-TRIANGLE NORMALS ***************/
309  /*********************************************************/
310 
311  // inherited from ccGenericMesh
312  bool hasTriNormals() const override;
313  // for compatibility
314  inline bool HasTriangleNormals() const { return hasTriNormals(); }
315  void getTriangleNormalIndexes(unsigned triangleIndex,
316  int& i1,
317  int& i2,
318  int& i3) const override;
319  bool getTriangleNormals(unsigned triangleIndex,
320  CCVector3& Na,
321  CCVector3& Nb,
322  CCVector3& Nc) const override;
323  bool getTriangleNormals(unsigned triangleIndex,
324  double Na[3],
325  double Nb[3],
326  double Nc[3]) const override;
327  bool getTriangleNormals(unsigned triangleIndex,
328  Eigen::Vector3d& Na,
329  Eigen::Vector3d& Nb,
330  Eigen::Vector3d& Nc) const override;
331  std::vector<Eigen::Vector3d> getTriangleNormals() const;
332  std::vector<CCVector3*> getTriangleNormalsPtr() const;
333  Eigen::Vector3d getTriangleNorm(size_t index) const;
334  bool setTriangleNorm(size_t index, const Eigen::Vector3d& triangle_normal);
335  bool setTriangleNormalIndexes(size_t triangleIndex,
336  CompressedNormType value);
338  bool addTriangleNorm(const CCVector3& N);
339  bool addTriangleNorm(const Eigen::Vector3d& N);
340  std::vector<Eigen::Vector3d> getTriangleNorms() const;
341  bool setTriangleNorms(const std::vector<Eigen::Vector3d>& triangle_normals);
342  bool addTriangleNorms(const std::vector<Eigen::Vector3d>& triangle_normals);
343 
345  return m_triNormals;
346  }
347 
350  bool autoReleaseOldTable = true);
351 
353  void clearTriNormals() { setTriNormsTable(nullptr); }
354 
356 
367 
369 
379 
381 
387  void addTriangleNormalIndexes(int i1, int i2, int i3);
388 
390 
395  void setTriangleNormalIndexes(unsigned triangleIndex,
396  int i1,
397  int i2,
398  int i3);
399 
402 
405 
406  /********************************************************/
407  /************ PER-TRIANGLE MATERIAL ***************/
408  /********************************************************/
409 
410  // inherited from ccGenericMesh
411  bool hasMaterials() const override;
412  const ccMaterialSet* getMaterialSet() const override { return m_materials; }
413  int getTriangleMtlIndex(unsigned triangleIndex) const override;
414 
416 
419 
422  return m_triMtlIndexes && m_triMtlIndexes->isAllocated();
423  }
424 
426 
436 
439 
441 
444  void addTriangleMtlIndex(int mtlIndex);
445 
448 
451  bool autoReleaseOldTable = true);
452 
455  const {
456  return m_triMtlIndexes;
457  }
458 
460 
464  void setTriangleMtlIndex(unsigned triangleIndex, int mtlIndex);
465 
467  void setMaterialSet(ccMaterialSet* materialSet,
468  bool autoReleaseOldMaterialSet = true);
469 
470  /******************************************************************/
471  /************ PER-TRIANGLE TEXTURE COORDINATE ***************/
472  /******************************************************************/
473 
474  // inherited from ccGenericMesh
475  bool hasTextures() const override;
477  return m_texCoords;
478  }
479  void getTriangleTexCoordinates(unsigned triIndex,
480  TexCoords2D*& tx1,
481  TexCoords2D*& tx2,
482  TexCoords2D*& tx3) const override;
483  void getTexCoordinates(unsigned index, TexCoords2D*& tx) const override;
484  bool hasPerTriangleTexCoordIndexes() const override {
485  return m_texCoordIndexes && m_texCoordIndexes->isAllocated();
486  }
487  void getTriangleTexCoordinatesIndexes(unsigned triangleIndex,
488  int& i1,
489  int& i2,
490  int& i3) const override;
491 
494  bool autoReleaseOldTable = true);
495 
497 
507 
510 
512 
518  void addTriangleTexCoordIndexes(int i1, int i2, int i3);
519 
521 
526  void setTriangleTexCoordIndexes(unsigned triangleIndex,
527  int i1,
528  int i2,
529  int i3);
530 
532 
535  bool computeNormals(bool perVertex);
536 
539 
542 
544 
549  unsigned nbIteration = 100,
550  PointCoordinateType factor = static_cast<PointCoordinateType>(0.01),
551  ecvProgressDialog* progressCb = nullptr);
552 
557  };
558 
561 
570 
573 
576 
578 
596  bool removeSelectedTriangles,
597  std::vector<int>* newIndexesOfRemainingTriangles = nullptr,
598  bool withChildEntities = false);
599 
601 
604  void swapTriangles(unsigned index1, unsigned index2);
605 
606  void removeTriangles(size_t index);
607 
609  void transformTriNormals(const ccGLMatrix& trans);
610 
612  static const unsigned char DefaultMergeDulicateVerticesLevel = 10;
613 
616  unsigned char octreeLevel = DefaultMergeDulicateVerticesLevel,
617  QWidget* parentWidget = nullptr);
618 
619 public: // some cloudViewer interface
622  std::vector<std::unordered_set<int>> adjacency_list_;
623 
625  std::vector<Eigen::Vector2d> triangle_uvs_;
626 
627  struct Material {
629  float f4[4] = {0};
630 
632  f4[0] = 0;
633  f4[1] = 0;
634  f4[2] = 0;
635  f4[3] = 0;
636  }
637 
638  MaterialParameter(const float v1,
639  const float v2,
640  const float v3,
641  const float v4) {
642  f4[0] = v1;
643  f4[1] = v2;
644  f4[2] = v3;
645  f4[3] = v4;
646  }
647 
648  MaterialParameter(const float v1, const float v2, const float v3) {
649  f4[0] = v1;
650  f4[1] = v2;
651  f4[2] = v3;
652  f4[3] = 1;
653  }
654 
655  MaterialParameter(const float v1, const float v2) {
656  f4[0] = v1;
657  f4[1] = v2;
658  f4[2] = 0;
659  f4[3] = 0;
660  }
661 
662  explicit MaterialParameter(const float v1) {
663  f4[0] = v1;
664  f4[1] = 0;
665  f4[2] = 0;
666  f4[3] = 0;
667  }
668 
669  static MaterialParameter CreateRGB(const float r,
670  const float g,
671  const float b) {
672  return {r, g, b, 1.f};
673  }
674 
675  float r() const { return f4[0]; }
676  float g() const { return f4[1]; }
677  float b() const { return f4[2]; }
678  float a() const { return f4[3]; }
679  };
680 
682  float baseMetallic = 0.f;
683  float baseRoughness = 1.f;
684  float baseReflectance = 0.5f;
685  float baseClearCoat = 0.f;
686  float baseClearCoatRoughness = 0.f;
687  float baseAnisotropy = 0.f;
688 
689  std::shared_ptr<cloudViewer::geometry::Image> albedo;
690  std::shared_ptr<cloudViewer::geometry::Image> normalMap;
691  std::shared_ptr<cloudViewer::geometry::Image> ambientOcclusion;
692  std::shared_ptr<cloudViewer::geometry::Image> metallic;
693  std::shared_ptr<cloudViewer::geometry::Image> roughness;
694  std::shared_ptr<cloudViewer::geometry::Image> reflectance;
695  std::shared_ptr<cloudViewer::geometry::Image> clearCoat;
696  std::shared_ptr<cloudViewer::geometry::Image> clearCoatRoughness;
697  std::shared_ptr<cloudViewer::geometry::Image> anisotropy;
698 
699  std::unordered_map<std::string, MaterialParameter> floatParameters;
700  std::unordered_map<std::string, cloudViewer::geometry::Image>
702  };
703 
704  std::vector<std::pair<std::string, Material>> materials_;
705 
707  std::vector<int> triangle_material_ids_;
709  std::vector<cloudViewer::geometry::Image> textures_;
710 
712  bool hasAdjacencyList() const {
713  return getVerticeSize() > 0 &&
714  adjacency_list_.size() == getVerticeSize();
715  }
716 
717  inline bool hasTriangleUvs() const {
718  return hasTriangles() && triangle_uvs_.size() == 3 * size();
719  }
720 
721  bool hasTriangleMaterialIds() const {
722  return hasTriangles() && triangle_material_ids_.size() == size();
723  }
724 
726  bool hasEigenTextures() const {
727  bool is_all_texture_valid = std::accumulate(
728  textures_.begin(), textures_.end(), true,
729  [](bool a, const cloudViewer::geometry::Image& b) {
730  return a && !b.IsEmpty();
731  });
732  return !textures_.empty() && is_all_texture_valid;
733  }
734 
735  inline virtual bool IsEmpty() const override {
736  return !HasVertices() || !hasTriangles();
737  }
738 
739  virtual Eigen::Vector3d GetMinBound() const override;
740  virtual Eigen::Vector3d GetMaxBound() const override;
741  virtual Eigen::Vector3d GetCenter() const override;
742  virtual ccBBox GetAxisAlignedBoundingBox() const override;
743  virtual ecvOrientedBBox GetOrientedBoundingBox() const override;
744  virtual ccMesh& Transform(const Eigen::Matrix4d& transformation) override;
745  virtual ccMesh& Translate(const Eigen::Vector3d& translation,
746  bool relative = true) override;
747  virtual ccMesh& Scale(const double s,
748  const Eigen::Vector3d& center) override;
749  virtual ccMesh& Rotate(const Eigen::Matrix3d& R,
750  const Eigen::Vector3d& center) override;
751 
755  ccMesh& PaintUniformColor(const Eigen::Vector3d& color);
756 
757  std::tuple<std::shared_ptr<ccMesh>, std::vector<size_t>> ComputeConvexHull()
758  const;
759 
768  std::unordered_map<Eigen::Vector2i,
769  double,
772  const std::unordered_map<
774  std::vector<int>,
776  edges_to_vertices,
777  double min_weight = std::numeric_limits<double>::lowest()) const;
778 
781  ccMesh& ComputeTriangleNormals(bool normalized = true);
782 
785  ccMesh& ComputeVertexNormals(bool normalized = true);
786 
790 
793 
797 
802 
806 
812 
818 
826 
836  std::shared_ptr<ccMesh> FilterSharpen(
837  int number_of_iterations,
838  double strength,
839  FilterScope scope = FilterScope::All) const;
840 
849  std::shared_ptr<ccMesh> FilterSmoothSimple(
850  int number_of_iterations,
851  FilterScope scope = FilterScope::All) const;
852 
863  std::shared_ptr<ccMesh> FilterSmoothLaplacian(
864  int number_of_iterations,
865  double lambda,
866  FilterScope scope = FilterScope::All) const;
867 
878  std::shared_ptr<ccMesh> FilterSmoothTaubin(
879  int number_of_iterations,
880  double lambda = 0.5,
881  double mu = -0.53,
882  FilterScope scope = FilterScope::All) const;
883 
888 
892  std::vector<Eigen::Vector2i> GetNonManifoldEdges(
893  bool allow_boundary_edges = true) const;
894 
899  bool IsEdgeManifold(bool allow_boundary_edges = true) const;
900 
904  std::vector<int> GetNonManifoldVertices() const;
905 
909  bool IsVertexManifold() const;
910 
913  std::vector<Eigen::Vector2i> GetSelfIntersectingTriangles() const;
914 
917  bool IsSelfIntersecting() const;
918 
921  bool IsBoundingBoxIntersecting(const ccMesh& other) const;
922 
925  bool IsIntersecting(const ccMesh& other) const;
926 
930  bool IsOrientable() const;
931 
935  bool IsWatertight() const;
936 
941 
944  std::unordered_map<Eigen::Vector2i,
945  std::vector<int>,
948 
951  std::unordered_map<Eigen::Vector2i,
952  std::vector<int>,
955 
958  double GetTriangleArea(size_t triangle_idx) const;
959 
961  static double ComputeTriangleArea(const Eigen::Vector3d& p0,
962  const Eigen::Vector3d& p1,
963  const Eigen::Vector3d& p2);
964 
965  static inline Eigen::Vector3i GetEigneOrderedTriangle(int vidx0,
966  int vidx1,
967  int vidx2) {
968  if (vidx0 > vidx2) {
969  std::swap(vidx0, vidx2);
970  }
971  if (vidx0 > vidx1) {
972  std::swap(vidx0, vidx1);
973  }
974  if (vidx1 > vidx2) {
975  std::swap(vidx1, vidx2);
976  }
977  return Eigen::Vector3i(vidx0, vidx1, vidx2);
978  }
979 
982  double GetSurfaceArea() const;
983 
986  double GetSurfaceArea(std::vector<double>& triangle_areas) const;
987 
991  double GetVolume() const;
992 
996  static Eigen::Vector4d ComputeTrianglePlane(const Eigen::Vector3d& p0,
997  const Eigen::Vector3d& p1,
998  const Eigen::Vector3d& p2);
999 
1002  Eigen::Vector4d GetTrianglePlane(size_t triangle_idx) const;
1003 
1005  static inline Eigen::Vector2i GetOrderedEdge(int vidx0, int vidx1) {
1006  return Eigen::Vector2i(std::min(vidx0, vidx1), std::max(vidx0, vidx1));
1007  }
1008 
1011  std::shared_ptr<ccPointCloud> SamplePointsUniformlyImpl(
1012  size_t number_of_points,
1013  std::vector<double>& triangle_areas,
1014  double surface_area,
1015  bool use_triangle_normal,
1016  int seed);
1017 
1025  std::shared_ptr<ccPointCloud> SamplePointsUniformly(
1026  size_t number_of_points,
1027  bool use_triangle_normal = false,
1028  int seed = -1);
1029 
1041  std::shared_ptr<ccPointCloud> SamplePointsPoissonDisk(
1042  size_t number_of_points,
1043  double init_factor = 5,
1044  const std::shared_ptr<ccPointCloud> pcl_init = nullptr,
1045  bool use_triangle_normal = false,
1046  int seed = -1);
1047 
1053  std::shared_ptr<ccMesh> SubdivideMidpoint(int number_of_iterations) const;
1054 
1060  std::shared_ptr<ccMesh> SubdivideLoop(int number_of_iterations) const;
1061 
1068  std::shared_ptr<ccMesh> SimplifyVertexClustering(
1069  double voxel_size,
1070  SimplificationContraction contraction =
1071  SimplificationContraction::Average) const;
1072 
1080  std::shared_ptr<ccMesh> SimplifyQuadricDecimation(
1081  int target_number_of_triangles,
1082  double maximum_error = std::numeric_limits<double>::infinity(),
1083  double boundary_weight = 1.0) const;
1084 
1094  std::shared_ptr<ccMesh> SelectByIndex(const std::vector<size_t>& indices,
1095  bool cleanup = true) const;
1096 
1101  std::shared_ptr<ccMesh> Crop(const ccBBox& bbox) const;
1102 
1107  std::shared_ptr<ccMesh> Crop(const ecvOrientedBBox& bbox) const;
1108 
1115  std::tuple<std::vector<int>, std::vector<size_t>, std::vector<double>>
1117 
1124  void RemoveTrianglesByIndex(const std::vector<size_t>& triangle_indices);
1125 
1132  void RemoveTrianglesByMask(const std::vector<bool>& triangle_mask);
1133 
1140  void RemoveVerticesByIndex(const std::vector<size_t>& vertex_indices);
1141 
1148  void RemoveVerticesByMask(const std::vector<bool>& vertex_mask);
1149 
1163  std::shared_ptr<ccMesh> DeformAsRigidAsPossible(
1164  const std::vector<int>& constraint_vertex_indices,
1165  const std::vector<Eigen::Vector3d>& constraint_vertex_positions,
1166  size_t max_iter,
1168  DeformAsRigidAsPossibleEnergy::Spokes,
1169  double smoothed_alpha = 0.01) const;
1170 
1182  static std::shared_ptr<ccMesh> CreateFromPointCloudAlphaShape(
1183  const ccPointCloud& pcd,
1184  double alpha,
1185  std::shared_ptr<cloudViewer::geometry::TetraMesh> tetra_mesh =
1186  nullptr,
1187  std::vector<size_t>* pt_map = nullptr);
1188 
1201  static std::shared_ptr<ccMesh> CreateFromPointCloudBallPivoting(
1202  const ccPointCloud& pcd, const std::vector<double>& radii);
1203 
1240  static std::tuple<std::shared_ptr<ccMesh>, std::vector<double>>
1242  size_t depth = 8,
1243  size_t width = 0,
1244  float scale = 1.1f,
1245  bool linear_fit = false,
1246  float point_weight = 2.f,
1247  float samples_per_node = 1.5f,
1248  int boundary_type = 2 /*BOUNDARY_NEUMANN*/,
1249  int n_threads = -1);
1250 
1256  static std::shared_ptr<ccMesh> CreateTetrahedron(
1257  double radius = 1.0, bool create_uv_map = false);
1258 
1264  static std::shared_ptr<ccMesh> CreateOctahedron(double radius = 1.0,
1265  bool create_uv_map = false);
1266 
1271  static std::shared_ptr<ccMesh> CreateIcosahedron(
1272  double radius = 1.0, bool create_uv_map = false);
1273 
1279  static std::shared_ptr<ccMesh> CreatePlane(double width = 1.0,
1280  double height = 1.0,
1281  bool create_uv_map = false);
1282 
1291  static std::shared_ptr<ccMesh> CreateBox(
1292  double width = 1.0,
1293  double height = 1.0,
1294  double depth = 1.0,
1295  bool create_uv_map = false,
1296  bool map_texture_to_each_face = false);
1297 
1308  static std::shared_ptr<ccMesh> CreateSphere(double radius = 1.0,
1309  int resolution = 20,
1310  bool create_uv_map = false);
1311 
1323  static std::shared_ptr<ccMesh> CreateCylinder(double radius = 1.0,
1324  double height = 2.0,
1325  int resolution = 20,
1326  int split = 4,
1327  bool create_uv_map = false);
1328 
1339  static std::shared_ptr<ccMesh> CreateCone(double radius = 1.0,
1340  double height = 2.0,
1341  int resolution = 20,
1342  int split = 1,
1343  bool create_uv_map = false);
1344 
1355  static std::shared_ptr<ccMesh> CreateTorus(double torus_radius = 1.0,
1356  double tube_radius = 0.5,
1357  int radial_resolution = 30,
1358  int tubular_resolution = 20);
1359 
1380  static std::shared_ptr<ccMesh> CreateArrow(double cylinder_radius = 1.0,
1381  double cone_radius = 1.5,
1382  double cylinder_height = 5.0,
1383  double cone_height = 4.0,
1384  int resolution = 20,
1385  int cylinder_split = 4,
1386  int cone_split = 1);
1387 
1393  static std::shared_ptr<ccMesh> CreateCoordinateFrame(
1394  double size = 1.0,
1395  const Eigen::Vector3d& origin = Eigen::Vector3d(0.0, 0.0, 0.0));
1396 
1407  static std::shared_ptr<ccMesh> CreateMobius(int length_split = 70,
1408  int width_split = 15,
1409  int twists = 1,
1410  double radius = 1,
1411  double flatness = 1,
1412  double width = 1,
1413  double scale = 1);
1414 
1415 protected:
1417  std::shared_ptr<ccMesh>& mesh,
1418  const std::vector<CCVector3>& prev_vertices,
1419  const std::vector<CCVector3>& prev_vertex_normals,
1420  const ColorsTableType& prev_vertex_colors,
1421  const std::vector<std::unordered_set<int>>& adjacency_list,
1422  double lambda,
1423  bool filter_vertex,
1424  bool filter_normal,
1425  bool filter_color) const;
1426 
1427 protected:
1428  // inherited from ccHObject
1430  bool toFile_MeOnly(QFile& out, short dataVersion) const override;
1431  short minimumFileVersion_MeOnly() const override;
1432  bool fromFile_MeOnly(QFile& in,
1433  short dataVersion,
1434  int flags,
1435  LoadedIDMap& oldToNewIDMap) override;
1436  void applyGLTransformation(const ccGLMatrix& trans) override;
1437  void onUpdateOf(ccHObject* obj) override;
1438  void onDeletionOf(const ccHObject* obj) override;
1439 
1443  const cloudViewer::VerticesIndexes& vertIndexes,
1444  const CCVector3& P,
1445  CCVector3d& weights) const;
1449  const CCVector3d& w,
1450  CCVector3& N,
1451  const Tuple3i* triNormIndexes = nullptr);
1455  const CCVector3& P,
1456  ecvColor::Rgb& C);
1457 
1459  bool pushSubdivide(/*PointCoordinateType maxArea, */ unsigned indexA,
1460  unsigned indexB,
1461  unsigned indexC);
1462 
1463  /*** EXTENDED CALL SCRIPTS (FOR CC_SUB_MESHES) ***/
1464 
1465  // 0 parameter
1466 #define ccMesh_extended_call0(baseName, recursiveName) \
1467  inline virtual void recursiveName() { \
1468  baseName(); \
1469  for (Container::iterator it = m_children.begin(); \
1470  it != m_children.end(); ++it) \
1471  if ((*it)->isA(CV_TYPES::SUB_MESH)) \
1472  static_cast<ccGenericMesh*>(*it)->baseName(); \
1473  }
1474 
1475  // 1 parameter
1476 #define ccMesh_extended_call1(baseName, param1Type, recursiveName) \
1477  inline virtual void recursiveName(param1Type p) { \
1478  baseName(p); \
1479  for (Container::iterator it = m_children.begin(); \
1480  it != m_children.end(); ++it) \
1481  if ((*it)->isA(CV_TYPES::SUB_MESH)) \
1482  static_cast<ccGenericMesh*>(*it)->baseName(p); \
1483  }
1484 
1485  // recursive equivalents of some of ccGenericMesh methods (applied to
1486  // sub-meshes as well)
1487  ccMesh_extended_call1(showNormals, bool, showNormals_extended)
1488 
1489 
1490  ccGenericPointCloud* m_associatedCloud;
1491 
1493  NormsIndexesTableType* m_triNormals;
1494 
1497 
1499  ccMaterialSet* m_materials;
1500 
1502  triangleIndexesContainer* m_triVertIndexes;
1503 
1505  unsigned m_globalIterator;
1507  cloudViewer::SimpleRefTriangle m_currentTriangle;
1508 
1510  ccBBox m_bBox;
1511 
1513  triangleMaterialIndexesSet* m_triMtlIndexes;
1514 
1518  triangleTexCoordIndexesSet* m_texCoordIndexes;
1519 
1523  triangleNormalsIndexesSet* m_triNormalIndexes;
1524 };
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
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
double normal[3]
int width
int size
int height
char type
math::float4 color
Array of RGB colors for each point.
Array of compressed 3D normals (single index)
Array of 2D texture coordinates.
Shareable array that can be properly inserted in the DB tree.
Definition: ecvArray.h:21
Bounding box structure.
Definition: ecvBBox.h:25
virtual bool hasNormals() const
Returns whether normals are enabled or not.
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
Generic mesh interface.
virtual bool materialsShown() const
Sets whether textures/material should be displayed or not.
virtual bool hasTriNormals() const =0
Returns whether the mesh has per-triangle normals.
virtual void showMaterials(bool state)
Sets whether textures should be displayed or not.
virtual unsigned capacity() const =0
Returns max capacity.
A 3D cloud interface with associated features (color, normals, octree, etc.)
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
Mesh (triangle) material.
Triangular mesh.
Definition: ecvMesh.h:35
bool getTriangleNormals(unsigned triangleIndex, double Na[3], double Nb[3], double Nc[3]) const override
bool IsIntersecting(const ccMesh &other) const
std::shared_ptr< ccMesh > Crop(const ccBBox &bbox) const
bool interpolateNormalsBC(unsigned triIndex, const CCVector3d &w, CCVector3 &N) override
Interpolates normal(s) inside a given triangle.
void getTriangleTexCoordinatesIndexes(unsigned triangleIndex, int &i1, int &i2, int &i3) const override
Returns the triplet of tex coords indexes for a given triangle.
CV_CLASS_ENUM getClassID() const override
Returns class ID.
Definition: ecvMesh.h:63
std::shared_ptr< ccMesh > FilterSmoothLaplacian(int number_of_iterations, double lambda, FilterScope scope=FilterScope::All) const
Function to smooth triangle mesh using Laplacian.
void getTriangleVertIndexes(size_t triangleIndex, Eigen::Vector3i &vertIndx) const
double GetTriangleArea(size_t triangle_idx) const
const ccMaterialSet * getMaterialSet() const override
Definition: ecvMesh.h:412
static std::tuple< std::shared_ptr< ccMesh >, std::vector< double > > CreateFromPointCloudPoisson(const ccPointCloud &pcd, size_t depth=8, size_t width=0, float scale=1.1f, bool linear_fit=false, float point_weight=2.f, float samples_per_node=1.5f, int boundary_type=2, int n_threads=-1)
Function that computes a triangle mesh from a oriented PointCloud pcd. This implements the Screened P...
TextureCoordsContainer * getTexCoordinatesTable() const override
Returns per-triangle texture coordinates array.
Definition: ecvMesh.h:476
static std::shared_ptr< ccMesh > CreateCylinder(double radius=1.0, double height=2.0, int resolution=20, int split=4, bool create_uv_map=false)
bool merge(const ccMesh *mesh, bool createSubMesh)
Merges another mesh into this one.
std::vector< int > GetNonManifoldVertices() const
ccMesh * cloneMesh(ccGenericPointCloud *vertices=nullptr, ccMaterialSet *clonedMaterials=nullptr, NormsIndexesTableType *clonedNormsTable=nullptr, TextureCoordsContainer *cloneTexCoords=nullptr)
Clones this entity.
void addEigenVertices(const std::vector< Eigen::Vector3d > &vertices)
NormsIndexesTableType * getTriNormsTable() const override
Returns per-triangle normals shared array.
Definition: ecvMesh.h:344
virtual ccMesh & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &center) override
Apply rotation to the geometry coordinates and normals. Given a rotation matrix , and center ,...
static std::shared_ptr< ccMesh > 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)
void getTriangleNormalIndexes(unsigned triangleIndex, int &i1, int &i2, int &i3) const override
Returns a triplet of normal indexes for a given triangle (if any)
void drawMeOnly(CC_DRAW_CONTEXT &context) override
Enables (OpenGL) stipple mask.
bool hasMaterials() const override
std::shared_ptr< ccMesh > SimplifyVertexClustering(double voxel_size, SimplificationContraction contraction=SimplificationContraction::Average) const
bool hasDisplayedScalarField() const override
Returns whether an active scalar field is available or not.
bool getTriangleNormals(unsigned triangleIndex, CCVector3 &Na, CCVector3 &Nb, CCVector3 &Nc) const override
Returns a given triangle normal.
std::shared_ptr< ccMesh > 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...
void invertPerTriangleNormals()
Invert per-triangle normals.
triangleIndexesContainer * getTrianglesPtr() const
Definition: ecvMesh.h:279
ccMesh * partialClone(const std::vector< unsigned > &triangleIndices, int *warnings=nullptr) const
Creates a new mesh from a selection of triangles (partial clone)
std::vector< Eigen::Vector3d > getTriangleNormals() const
ccMesh & RemoveDuplicatedTriangles()
Function that removes duplicated triangles, i.e., removes triangles that reference the same three ver...
void applyGLTransformation(const ccGLMatrix &trans) override
Applies a GL transformation to the entity.
void RemoveTrianglesByMask(const std::vector< bool > &triangle_mask)
This function removes the triangles that are masked in triangle_mask. Call RemoveUnreferencedVertices...
std::shared_ptr< ccMesh > SelectByIndex(const std::vector< size_t > &indices, bool cleanup=true) const
virtual void getTriangleVertices(unsigned triangleIndex, double A[3], double B[3], double C[3]) const override
ccMesh * subdivide(PointCoordinateType maxArea) const
bool laplacianSmooth(unsigned nbIteration=100, PointCoordinateType factor=static_cast< PointCoordinateType >(0.01), ecvProgressDialog *progressCb=nullptr)
Laplacian smoothing.
const triangleMaterialIndexesSet * getTriangleMtlIndexesTable() const
Returns the per-triangle material indexes array.
Definition: ecvMesh.h:454
cloudViewer::VerticesIndexes * getTriangleVertIndexes(unsigned triangleIndex) override
Returns the indexes of the vertices of a given triangle.
bool hasAdjacencyList() const
Returns true if the mesh contains adjacency normals.
Definition: ecvMesh.h:712
virtual bool IsEmpty() const override
Definition: ecvMesh.h:735
bool normalsShown() const override
Returns whether normals are shown or not.
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...
ccMesh operator+(const ccMesh &mesh) const
bool reservePerTriangleMtlIndexes()
Reserves memory to store per-triangle material index.
bool addTriangleNorm(const Eigen::Vector3d &N)
void flipTriangles()
Flips the triangle.
static std::shared_ptr< ccMesh > CreateCoordinateFrame(double size=1.0, const Eigen::Vector3d &origin=Eigen::Vector3d(0.0, 0.0, 0.0))
void setTriangleMtlIndexesTable(triangleMaterialIndexesSet *matIndexesTable, bool autoReleaseOldTable=true)
Sets per-triangle material indexes array.
void setVertexNormal(size_t index, const Eigen::Vector3d &normal)
std::vector< Eigen::Vector3i > getTriangles() const
bool processScalarField(MESH_SCALAR_FIELD_PROCESS process)
void toggleMaterials() override
Toggles material display state.
Definition: ecvMesh.h:233
cloudViewer::GenericTriangle * _getTriangle(unsigned triangleIndex) override
Returns the ith triangle.
void addTriangles(const std::vector< Eigen::Vector3i > &triangles)
Definition: ecvMesh.h:265
bool IsVertexManifold() const
virtual ccMesh & 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...
bool setTriangleNorm(size_t index, const Eigen::Vector3d &triangle_normal)
static ccMesh * TriangulateTwoPolylines(ccPolyline *p1, ccPolyline *p2, CCVector3 *projectionDir=nullptr)
Creates a Delaunay 2.5D mesh from two polylines.
void removePerTriangleNormalIndexes()
Removes any per-triangle triplets of normal indexes.
std::vector< int > triangle_material_ids_
List of material ids.
Definition: ecvMesh.h:707
std::unordered_map< Eigen::Vector2i, std::vector< int >, cloudViewer::utility::hash_eigen< Eigen::Vector2i > > GetEdgeToTrianglesMap() const
int EulerPoincareCharacteristic() const
bool OrientTriangles()
bool convertMaterialsToVertexColors()
Converts materials to vertex colors.
short minimumFileVersion_MeOnly() const override
void addVertice(const Eigen::Vector3d &vertice)
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
double GetSurfaceArea() const
void addTriangle(const Eigen::Vector3i &index)
Definition: ecvMesh.h:260
void setTriangle(size_t index, const Eigen::Vector3i &triangle)
ccMesh & RemoveDuplicatedVertices()
Function that removes duplicated verties, i.e., vertices that have identical coordinates.
static std::shared_ptr< ccMesh > CreateMobius(int length_split=70, int width_split=15, int twists=1, double radius=1, double flatness=1, double width=1, double scale=1)
ccMesh(ccGenericPointCloud *vertices=nullptr)
Default ccMesh constructor.
static std::shared_ptr< ccMesh > CreateIcosahedron(double radius=1.0, bool create_uv_map=false)
void getTriangleTexCoordinates(unsigned triIndex, TexCoords2D *&tx1, TexCoords2D *&tx2, TexCoords2D *&tx3) const override
Returns per-triangle texture coordinates (pointer to)
void setTriNormsTable(NormsIndexesTableType *triNormsTable, bool autoReleaseOldTable=true)
Sets per-triangle normals array (may be shared)
std::vector< Eigen::Vector2d > triangle_uvs_
List of uv coordinates per triangle.
Definition: ecvMesh.h:625
static cloudViewer::VerticesIndexes GetOrderedTriangle(int vidx0, int vidx1, int vidx2)
Definition: ecvMesh.h:92
void transformTriNormals(const ccGLMatrix &trans)
Transforms the mesh per-triangle normals.
void swapTriangles(unsigned index1, unsigned index2)
Swaps two triangles.
std::shared_ptr< ccMesh > Crop(const ecvOrientedBBox &bbox) const
ccMesh(const ccMesh &mesh)
bool IsSelfIntersecting() const
Eigen::Vector3d getTriangleNorm(size_t index) const
std::vector< Eigen::Vector3d > getVertexColors() const
std::shared_ptr< ccMesh > 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...
bool HasVertexNormals() const
ccMesh & RemoveNonManifoldEdges()
Function that removes all non-manifold edges, by successively deleting triangles with the smallest su...
bool hasColors() const override
Returns whether colors are enabled or not.
MESH_SCALAR_FIELD_PROCESS
Mesh scalar field processes.
Definition: ecvMesh.h:554
@ ENHANCE_MESH_SF
Definition: ecvMesh.h:556
@ SMOOTH_MESH_SF
Definition: ecvMesh.h:555
bool getColorFromMaterial(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &C, bool interpolateColorIfNoTexture) override
bool pushSubdivide(unsigned indexA, unsigned indexB, unsigned indexC)
Used internally by 'subdivide'.
void setAssociatedCloud(ccGenericPointCloud *cloud)
Sets the associated vertices cloud (warning)
static ccMesh * Triangulate(ccGenericPointCloud *cloud, cloudViewer::TRIANGULATION_TYPES type, bool updateNormals=false, PointCoordinateType maxEdgeLength=0, unsigned char dim=2)
Creates a Delaunay 2.5D mesh from a point cloud.
std::vector< Eigen::Vector3d > getTriangleNorms() const
std::vector< std::unordered_set< int > > adjacency_list_
Definition: ecvMesh.h:622
void addTriangleMtlIndex(int mtlIndex)
Adds triangle material index for next triangle.
void setTriangleMtlIndex(unsigned triangleIndex, int mtlIndex)
Sets triangle material indexes.
std::shared_ptr< ccMesh > SubdivideMidpoint(int number_of_iterations) const
void RemoveTrianglesByIndex(const std::vector< size_t > &triangle_indices)
This function removes the triangles with index in triangle_indices. Call RemoveUnreferencedVertices t...
void clearTriNormals()
Removes per-triangle normals.
Definition: ecvMesh.h:353
bool computePerTriangleNormals()
Computes per-triangle normals.
void computeInterpolationWeights(const cloudViewer::VerticesIndexes &vertIndexes, const CCVector3 &P, CCVector3d &weights) const
ccMesh(cloudViewer::GenericIndexedMesh *giMesh, ccGenericPointCloud *giVertices)
ccMesh constructor (from a cloudViewer::GenericIndexedMesh)
const std::vector< CCVector3 > & getVertices() const
void setEigenVertices(const std::vector< Eigen::Vector3d > &vertices)
static std::shared_ptr< ccMesh > 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)
void setTriangleNormalIndexes(unsigned triangleIndex, int i1, int i2, int i3)
Sets a triplet of normal indexes for a given triangle.
void setMaterialSet(ccMaterialSet *materialSet, bool autoReleaseOldMaterialSet=true)
Sets associated material set (may be shared)
void setTriangles(const std::vector< Eigen::Vector3i > &triangles)
std::unordered_map< Eigen::Vector2i, std::vector< int >, cloudViewer::utility::hash_eigen< Eigen::Vector2i > > GetEdgeToVerticesMap() const
bool isSerializable() const override
Returns whether object is serializable of not.
Definition: ecvMesh.h:139
bool reserve(std::size_t n)
Reserves the memory to store the vertex indexes (3 per triangle)
cloudViewer::VerticesIndexes * getNextTriangleVertIndexes() override
ccGenericPointCloud * getAssociatedCloud() const override
Returns the vertices cloud.
Definition: ecvMesh.h:143
void shiftTriangleIndexes(unsigned shift)
Shifts all triangles indexes.
static std::shared_ptr< ccMesh > CreateTetrahedron(double radius=1.0, bool create_uv_map=false)
double GetVolume() const
void FilterSmoothLaplacianHelper(std::shared_ptr< ccMesh > &mesh, const std::vector< CCVector3 > &prev_vertices, const std::vector< CCVector3 > &prev_vertex_normals, const ColorsTableType &prev_vertex_colors, const std::vector< std::unordered_set< int >> &adjacency_list, double lambda, bool filter_vertex, bool filter_normal, bool filter_color) const
bool hasEigenTextures() const
Returns true if the mesh has texture.
Definition: ecvMesh.h:726
void addVertexColors(const std::vector< Eigen::Vector3d > &colors)
void addVertexNormal(const Eigen::Vector3d &normal)
void addTriangleTexCoordIndexes(int i1, int i2, int i3)
Adds a triplet of tex coords indexes for next triangle.
bool normalsAvailable() const override
Returns whether normals are available.
Definition: ecvMesh.h:215
std::vector< Eigen::Vector2i > GetSelfIntersectingTriangles() const
static std::shared_ptr< ccMesh > CreateCone(double radius=1.0, double height=2.0, int resolution=20, int split=1, bool create_uv_map=false)
std::shared_ptr< ccMesh > SubdivideLoop(int number_of_iterations) const
bool hasTextures() const override
Returns whether textures are available for this mesh.
bool setTriangleNormalIndexes(size_t triangleIndex, CompressedNormType value)
static std::shared_ptr< ccMesh > CreateFromPointCloudBallPivoting(const ccPointCloud &pcd, const std::vector< double > &radii)
void setVertexNormals(const std::vector< Eigen::Vector3d > &normals)
ccMesh & RemoveUnreferencedVertices()
This function removes vertices from the triangle mesh that are not referenced in any triangle of the ...
Eigen::Vector3d getVertice(size_t index) const
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
static Eigen::Vector4d ComputeTrianglePlane(const Eigen::Vector3d &p0, const Eigen::Vector3d &p1, const Eigen::Vector3d &p2)
std::vector< Eigen::Vector3d > getEigenVertices() const
unsigned getUniqueIDForDisplay() const override
Returns object unqiue ID used for display.
Eigen::Vector4d GetTrianglePlane(size_t triangle_idx) const
void placeIteratorAtBeginning() override
Places the mesh iterator at the beginning.
void addTriangle(unsigned i1, unsigned i2, unsigned i3)
Adds a triangle to the mesh.
void removePerTriangleTexCoordIndexes()
Remove per-triangle tex coords indexes.
bool reservePerTriangleNormalIndexes()
Reserves memory to store per-triangle triplets of normal indexes.
bool hasPerTriangleTexCoordIndexes() const override
Returns whether this mesh as per-triangle triplets of tex coords indexes.
Definition: ecvMesh.h:484
virtual ccBBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
static std::shared_ptr< ccMesh > CreatePlane(double width=1.0, double height=1.0, bool create_uv_map=false)
void setTexCoordinatesTable(TextureCoordsContainer *texCoordsTable, bool autoReleaseOldTable=true)
Sets per-triangle texture coordinates array (may be shared)
bool HasVertices() const
Definition: ecvMesh.h:208
static Eigen::Vector3i GetEigneOrderedTriangle(int vidx0, int vidx1, int vidx2)
Definition: ecvMesh.h:965
bool interpolateNormals(unsigned triIndex, const CCVector3 &P, CCVector3 &N) override
Interpolates normal(s) inside a given triangle.
ccMesh & PaintUniformColor(const Eigen::Vector3d &color)
Assigns each vertex in the ccMesh the same color.
CompressedNormType getTriangleNormalIndexes(size_t triangleIndex)
std::shared_ptr< ccMesh > SimplifyQuadricDecimation(int target_number_of_triangles, double maximum_error=std::numeric_limits< double >::infinity(), double boundary_weight=1.0) const
unsigned int getVerticeSize() const
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...
virtual void getTriangleVertices(unsigned triangleIndex, CCVector3 &A, CCVector3 &B, CCVector3 &C) const override
Returns the vertices of a given triangle.
std::shared_ptr< ccPointCloud > SamplePointsPoissonDisk(size_t number_of_points, double init_factor=5, const std::shared_ptr< ccPointCloud > pcl_init=nullptr, bool use_triangle_normal=false, int seed=-1)
void removeTriangles(size_t index)
static std::shared_ptr< ccMesh > CreateFromPointCloudAlphaShape(const ccPointCloud &pcd, double alpha, std::shared_ptr< cloudViewer::geometry::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 ...
ccMesh & ComputeAdjacencyList()
Function to compute adjacency list, call before adjacency list is.
bool resize(size_t n)
Resizes the array of vertex indexes (3 per triangle)
void setVertexColors(const std::vector< Eigen::Vector3d > &colors)
Eigen::Vector3d getVertexColor(size_t index) const
bool resizeAssociatedCloud(std::size_t n)
std::shared_ptr< ccPointCloud > SamplePointsUniformlyImpl(size_t number_of_points, std::vector< double > &triangle_areas, double surface_area, bool use_triangle_normal, int seed)
bool arePerTriangleNormalsEnabled() const
Returns whether per triangle normals are enabled.
std::shared_ptr< ccPointCloud > SamplePointsUniformly(size_t number_of_points, bool use_triangle_normal=false, int seed=-1)
static std::shared_ptr< ccMesh > CreateSphere(double radius=1.0, int resolution=20, bool create_uv_map=false)
ccMesh & operator+=(const ccMesh &mesh)
void addTriangleNormalIndexes(int i1, int i2, int i3)
Adds a triplet of normal indexes for next triangle.
void getTexCoordinates(unsigned index, TexCoords2D *&tx) const override
bool reserveAssociatedCloud(std::size_t n, bool init_color=false, bool init_normal=false)
std::tuple< std::shared_ptr< ccMesh >, std::vector< size_t > > ComputeConvexHull() const
ccMesh & RemoveDegenerateTriangles()
Function that removes degenerate triangles, i.e., triangles that reference a single vertex multiple t...
std::vector< CCVector3 * > getTriangleNormalsPtr() const
bool reservePerTriangleTexCoordIndexes()
Reserves memory to store per-triangle triplets of tex coords indexes.
void setVertexColor(size_t index, const Eigen::Vector3d &color)
ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
ccMesh * createNewMeshFromSelection(bool removeSelectedTriangles, std::vector< int > *newIndexesOfRemainingTriangles=nullptr, bool withChildEntities=false)
Creates a new mesh with the selected vertices only.
bool getVertexColorFromMaterial(unsigned triIndex, unsigned char vertIndex, ecvColor::Rgb &C, bool returnColorIfNoTexture) override
bool IsOrientable() const
double GetSurfaceArea(std::vector< double > &triangle_areas) const
bool hasNormals() const override
Returns whether normals are enabled or not.
bool computePerVertexNormals()
Computes per-vertex normals.
void refreshBB() override
Forces bounding-box update.
virtual ecvOrientedBBox GetOrientedBoundingBox() const override
void clear()
static std::shared_ptr< ccMesh > CreateTorus(double torus_radius=1.0, double tube_radius=0.5, int radial_resolution=30, int tubular_resolution=20)
bool hasScalarFields() const override
Returns whether one or more scalar fields are instantiated.
void addTriangle(const cloudViewer::VerticesIndexes &triangle)
bool IsWatertight() const
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...
bool IsBoundingBoxIntersecting(const ccMesh &other) const
std::vector< Eigen::Vector3d > getVertexNormals() const
void onDeletionOf(const ccHObject *obj) override
This method is called when another object is deleted.
std::vector< CCVector3 > & getVerticesPtr()
bool interpolateColors(const cloudViewer::VerticesIndexes &vertIndexes, const CCVector3 &P, ecvColor::Rgb &C)
void computeInterpolationWeights(unsigned triIndex, const CCVector3 &P, CCVector3d &weights) const override
Returns the (barycentric) interpolation weights for a given triangle.
~ccMesh() override
Default destructor.
std::unordered_map< Eigen::Vector2i, double, cloudViewer::utility::hash_eigen< Eigen::Vector2i > > ComputeEdgeWeightsCot(const std::unordered_map< Eigen::Vector2i, std::vector< int >, cloudViewer::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...
void setTriangleTexCoordIndexes(unsigned triangleIndex, int i1, int i2, int i3)
Sets a triplet of tex coords indexes for a given triangle.
virtual unsigned size() const override
Returns the number of triangles.
bool IsEdgeManifold(bool allow_boundary_edges=true) const
Eigen::Vector3i getTriangle(size_t index) const
void removePerTriangleMtlIndexes()
Removes any per-triangle material indexes.
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
bool setTriangleNorms(const std::vector< Eigen::Vector3d > &triangle_normals)
void forEach(genericTriangleAction action) override
Fast iteration mechanism.
int getTriangleMtlIndex(unsigned triangleIndex) const override
Returns a given triangle material indexes.
void setVertice(size_t index, const Eigen::Vector3d &vertice)
bool HasTriangleNormals() const
Definition: ecvMesh.h:314
bool hasTriangleMaterialIds() const
Definition: ecvMesh.h:721
std::shared_ptr< ccMesh > FilterSmoothSimple(int number_of_iterations, FilterScope scope=FilterScope::All) const
Function to smooth triangle mesh with simple neighbour average.
std::vector< cloudViewer::geometry::Image > textures_
Textures of the image.
Definition: ecvMesh.h:709
bool addTriangleNorm(const CCVector3 &N)
cloudViewer::GenericTriangle * _getNextTriangle() override
Returns the next triangle (relatively to the global iterator position)
static double ComputeTriangleArea(const Eigen::Vector3d &p0, const Eigen::Vector3d &p1, const Eigen::Vector3d &p2)
Function that computes the area of a mesh triangle.
void shrinkVertexToFit()
bool mergeDuplicatedVertices(unsigned char octreeLevel=DefaultMergeDulicateVerticesLevel, QWidget *parentWidget=nullptr)
Merges duplicated vertices.
ccMesh & ComputeVertexNormals(bool normalized=true)
Function to compute vertex normals, usually called before rendering.
void getBoundingBox(CCVector3 &bbMin, CCVector3 &bbMax) override
Returns the mesh bounding-box.
ccMesh & operator=(const ccMesh &mesh)
ColorsTableType * getVertexColorsPtr()
static Eigen::Vector2i GetOrderedEdge(int vidx0, int vidx1)
Helper function to get an edge with ordered vertex indices.
Definition: ecvMesh.h:1005
Eigen::Vector3d getVertexNormal(size_t index) const
void onUpdateOf(ccHObject *obj) override
This method is called when another object (geometry) is updated.
std::shared_ptr< ccMesh > FilterSharpen(int number_of_iterations, double strength, FilterScope scope=FilterScope::All) const
Function to sharpen triangle mesh.
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
void addVertexNormals(const std::vector< Eigen::Vector3d > &normals)
ccMesh(const std::vector< Eigen::Vector3d > &vertices, const std::vector< Eigen::Vector3i > &triangles)
Parameterized Constructor.
void shrinkToFit()
Removes unused capacity.
Definition: ecvMesh.h:302
ccMesh & MergeCloseVertices(double eps)
Function that will merge close by vertices to a single one. The vertex position, normal and color wil...
std::vector< std::pair< std::string, Material > > materials_
Definition: ecvMesh.h:704
void addVertexColor(const Eigen::Vector3d &color)
virtual ccMesh & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
bool addTriangleNorms(const std::vector< Eigen::Vector3d > &triangle_normals)
unsigned capacity() const override
Returns max capacity.
bool hasPerTriangleMtlIndexes() const
Returns whether this mesh as per-triangle material index.
Definition: ecvMesh.h:421
void invertNormals()
Inverts normals (if any)
bool hasTriangleUvs() const
Definition: ecvMesh.h:717
bool interpolateNormals(const cloudViewer::VerticesIndexes &vertIndexes, const CCVector3d &w, CCVector3 &N, const Tuple3i *triNormIndexes=nullptr)
bool getTriangleNormals(unsigned triangleIndex, Eigen::Vector3d &Na, Eigen::Vector3d &Nb, Eigen::Vector3d &Nc) const override
const ccGLMatrix & getGLTransformationHistory() const override
Returns the transformation 'history' matrix.
std::vector< Eigen::Vector2i > GetNonManifoldEdges(bool allow_boundary_edges=true) const
static std::shared_ptr< ccMesh > CreateOctahedron(double radius=1.0, bool create_uv_map=false)
ccMesh & ComputeTriangleNormals(bool normalized=true)
Function to compute triangle normals, usually called before rendering.
virtual const cloudViewer::VerticesIndexes * getTriangleVertIndexes(unsigned triangleIndex) const
virtual ccMesh & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
bool computeNormals(bool perVertex)
Computes normals.
ccMesh & NormalizeNormals()
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
bool hasTriNormals() const override
Returns whether the mesh has per-triangle normals.
bool interpolateColors(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &C) override
Interpolates RGB colors inside a given triangle.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Colored polyline.
Definition: ecvPolyline.h:24
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
A generic mesh with index-based vertex access.
virtual unsigned size() const =0
Returns the number of triangles.
std::function< void(GenericTriangle &)> genericTriangleAction
Generic function to apply to a triangle (used by foreach)
Definition: GenericMesh.h:53
FilterScope
Indicates the scope of filter operations.
Definition: GenericMesh.h:44
SimplificationContraction
Indicates the method that is used for mesh simplification if multiple vertices are combined to a sing...
Definition: GenericMesh.h:35
virtual bool hasTriangles() const
Definition: GenericMesh.h:60
A generic triangle interface.
The Image class stores image with customizable width, height, num of channels and bytes per channel.
Definition: Image.h:33
RGB color structure.
Definition: ecvColorTypes.h:49
Graphical progress indicator (thread-safe)
double colors[3]
double normals[3]
__device__ __forceinline__ float infinity()
Definition: result_set.h:36
int min(int a, int b)
Definition: cutil_math.h:53
int max(int a, int b)
Definition: cutil_math.h:48
unsigned int CompressedNormType
Compressed normals type.
Definition: ecvBasicTypes.h:16
#define ccMesh_extended_call1(baseName, param1Type, recursiveName)
Definition: ecvMesh.h:1476
Helper functions for the ml ops.
ImGuiContext * context
Definition: Window.cpp:76
@ MESH
Definition: CVTypes.h:105
Generic file read and write utility for python interface.
TRIANGULATION_TYPES
Triangulation types.
Eigen::Matrix< Index, 3, 1 > Vector3i
Definition: knncpp.h:30
Eigen::Matrix< Index, 2, 1 > Vector2i
Definition: knncpp.h:29
void swap(cloudViewer::core::SmallVectorImpl< T > &LHS, cloudViewer::core::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Definition: SmallVector.h:1370
unsigned char octreeLevel
std::vector< PointCoordinateType > radii
Definition: qM3C2Tools.cpp:42
2D texture coordinates
Display context.
MaterialParameter(const float v1, const float v2, const float v3, const float v4)
Definition: ecvMesh.h:638
MaterialParameter(const float v1, const float v2, const float v3)
Definition: ecvMesh.h:648
static MaterialParameter CreateRGB(const float r, const float g, const float b)
Definition: ecvMesh.h:669
MaterialParameter(const float v1)
Definition: ecvMesh.h:662
MaterialParameter(const float v1, const float v2)
Definition: ecvMesh.h:655
std::shared_ptr< cloudViewer::geometry::Image > anisotropy
Definition: ecvMesh.h:697
std::shared_ptr< cloudViewer::geometry::Image > ambientOcclusion
Definition: ecvMesh.h:691
std::shared_ptr< cloudViewer::geometry::Image > metallic
Definition: ecvMesh.h:692
std::shared_ptr< cloudViewer::geometry::Image > clearCoat
Definition: ecvMesh.h:695
std::unordered_map< std::string, MaterialParameter > floatParameters
Definition: ecvMesh.h:699
std::shared_ptr< cloudViewer::geometry::Image > reflectance
Definition: ecvMesh.h:694
MaterialParameter baseColor
Definition: ecvMesh.h:681
std::shared_ptr< cloudViewer::geometry::Image > albedo
Definition: ecvMesh.h:689
std::unordered_map< std::string, cloudViewer::geometry::Image > additionalMaps
Definition: ecvMesh.h:701
std::shared_ptr< cloudViewer::geometry::Image > clearCoatRoughness
Definition: ecvMesh.h:696
std::shared_ptr< cloudViewer::geometry::Image > roughness
Definition: ecvMesh.h:693
std::shared_ptr< cloudViewer::geometry::Image > normalMap
Definition: ecvMesh.h:690
Triangle described by the indexes of its 3 vertices.