ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvGenericMesh.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 // CV_CORE_LIB
11 #include <GenericIndexedMesh.h>
12 
13 // LOCAL
14 #include "ecvAdvancedTypes.h"
15 #include "ecvBBox.h"
16 #include "ecvShiftedObject.h"
17 
18 namespace cloudViewer {
19 class GenericProgressCallback;
20 class ReferenceCloud;
21 } // namespace cloudViewer
22 
24 class ccPointCloud;
25 class ccMaterialSet;
26 
29  public ccShiftedObject {
30 public:
32 
34  ccGenericMesh(QString name = QString());
35 
37  ~ccGenericMesh() override = default;
38 
39  // inherited methods (ccDrawableObject)
40  void showNormals(bool state) override;
41 
42  // inherited methods (ccHObject)
43  bool isSerializable() const override { return true; }
44 
47 
49  virtual void refreshBB() = 0;
50 
52  virtual unsigned capacity() const = 0;
53 
55  virtual bool hasMaterials() const = 0;
56 
58  virtual const ccMaterialSet* getMaterialSet() const = 0;
59 
61  virtual int getTriangleMtlIndex(unsigned triangleIndex) const = 0;
62 
64  virtual bool hasTextures() const = 0;
65 
68 
70  virtual void getTriangleTexCoordinates(unsigned triIndex,
71  TexCoords2D*& tx1,
72  TexCoords2D*& tx2,
73  TexCoords2D*& tx3) const = 0;
74  virtual void getTexCoordinates(unsigned index, TexCoords2D*& tx) const = 0;
75 
77  virtual bool hasPerTriangleTexCoordIndexes() const = 0;
78 
80 
85  virtual void getTriangleTexCoordinatesIndexes(unsigned triangleIndex,
86  int& i1,
87  int& i2,
88  int& i3) const = 0;
89 
91  virtual bool hasTriNormals() const = 0;
92 
94 
99  virtual void getTriangleNormalIndexes(unsigned triangleIndex,
100  int& i1,
101  int& i2,
102  int& i3) const = 0;
103 
105 
107  virtual bool getTriangleNormals(unsigned triangleIndex,
108  CCVector3& Na,
109  CCVector3& Nb,
110  CCVector3& Nc) const = 0;
111  virtual bool getTriangleNormals(unsigned triangleIndex,
112  double Na[3],
113  double Nb[3],
114  double Nc[3]) const {
115  return false;
116  };
117  virtual bool getTriangleNormals(unsigned triangleIndex,
118  Eigen::Vector3d& Na,
119  Eigen::Vector3d& Nb,
120  Eigen::Vector3d& Nc) const {
121  return false;
122  };
123 
126 
128  virtual void computeInterpolationWeights(unsigned triIndex,
129  const CCVector3& P,
130  CCVector3d& weights) const;
131 
133 
138  virtual bool interpolateNormalsBC(unsigned triIndex,
139  const CCVector3d& w,
140  CCVector3& N) = 0;
141 
143 
148  virtual bool interpolateColors(unsigned triIndex,
149  const CCVector3& P,
150  ecvColor::Rgb& C) = 0;
151 
154  // \param P point where to grab color (should be inside the triangle!)
155  // \param[out] C vertex color
156  // \param interpolateColorIfNoTexture whether to return the color
157  // interpolated from the RGB field if no texture/material is associated to
158  // the given triangles \return success
159  //**/
160  virtual bool getColorFromMaterial(unsigned triIndex,
161  const CCVector3& P,
162  ecvColor::Rgb& C,
163  bool interpolateColorIfNoTexture) = 0;
164 
167  // \param vertIndex vertex index inside triangle (i.e. 0, 1 or 2!)
168  // \param[out] C vertex color
169  // \param returnColorIfNoTexture whether to return the color from the
170  // vertex RGB field if no texture/material is associated to the given
171  // triangle \return success
172  //**/
173  virtual bool getVertexColorFromMaterial(unsigned triIndex,
174  unsigned char vertIndex,
175  ecvColor::Rgb& C,
176  bool returnColorIfNoTexture) = 0;
177 
179  virtual bool isShownAsWire() const { return m_showWired; }
180 
182  virtual void showWired(bool state) { m_showWired = state; }
183 
185  virtual bool isShownAsPoints() const { return m_showPoints; }
186 
189  virtual void showPoints(bool state) { m_showPoints = state; }
190 
192  virtual bool triNormsShown() const { return m_triNormsShown; }
193 
195  virtual void showTriNorms(bool state) { m_triNormsShown = state; }
196 
198  virtual bool materialsShown() const { return m_materialsShown; }
199 
201  virtual void showMaterials(bool state) { m_materialsShown = state; }
202 
204  virtual bool stipplingEnabled() const { return m_stippling; }
205 
207  void enableStippling(bool state) { m_stippling = state; }
208 
211  bool densityBased,
212  double samplingParameter,
213  bool withNormals,
214  bool withRGB,
215  bool withTexture,
216  cloudViewer::GenericProgressCallback* pDlg = nullptr);
217 
219 
222 
224  virtual bool trianglePicking(const CCVector2d& clickPos,
225  const ccGLCameraParameters& camera,
226  int& nearestTriIndex,
227  double& nearestSquareDist,
228  CCVector3d& nearestPoint,
229  CCVector3d* barycentricCoords = nullptr) const;
230 
232  virtual bool trianglePicking(unsigned triIndex,
233  const CCVector2d& clickPos,
234  const ccGLCameraParameters& camera,
235  CCVector3d& point,
236  CCVector3d* barycentricCoords = nullptr) const;
237 
240  bool computePointPosition(unsigned triIndex,
241  const CCVector2d& uv,
242  CCVector3& P,
243  bool warningIfOutside = true) const;
244 
247  ccGenericMesh** mesh = nullptr);
248 
249  // inherited methods (ccShiftedObject)
250  void setGlobalShift(const CCVector3d& shift) override;
251  void setGlobalScale(double scale) override;
252  const CCVector3d& getGlobalShift() const override;
253  double getGlobalScale() const override;
254 
255  // inherited methods (GenericIndexedMesh)
256  bool normalsAvailable() const override { return hasNormals(); }
257 
258  bool updateTextures(const std::string& texture_file);
259  bool updateTextures(const std::vector<std::string>& texture_files);
260 
261 protected:
262  // inherited from ccHObject
263  bool toFile_MeOnly(QFile& out, short dataVersion) const override;
264  short minimumFileVersion_MeOnly() const override;
265  bool fromFile_MeOnly(QFile& in,
266  short dataVersion,
267  int flags,
268  LoadedIDMap& oldToNewIDMap) override;
269 
270  // Static arrays for OpenGL drawing
274 
276  virtual bool trianglePicking(unsigned triIndex,
277  const CCVector2d& clickPos,
278  const ccGLMatrix& trans,
279  bool noGLTrans,
280  const ccGenericPointCloud& vertices,
281  const ccGLCameraParameters& camera,
282  CCVector3d& point,
283  CCVector3d* barycentricCoords = nullptr) const;
284 
286 
288  static unsigned* GetWireVertexIndexes();
289 
291  // static void EnableGLStippleMask(const QOpenGLContext* context, bool
292  // state);
293 
294  // inherited from ccHObject
296 
299 
302 
305 
308 
311 
314 };
#define CV_DB_LIB_API
Definition: CV_db.h:15
std::string name
math::float2 uv
Array of compressed 3D normals (single index)
Array of 2D texture coordinates.
virtual bool hasNormals() const
Returns whether normals are enabled or not.
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
Generic mesh interface.
virtual TextureCoordsContainer * getTexCoordinatesTable() const =0
Returns per-triangle texture coordinates array.
virtual bool getTriangleNormals(unsigned triangleIndex, double Na[3], double Nb[3], double Nc[3]) const
virtual void showPoints(bool state)
bool updateTextures(const std::string &texture_file)
virtual bool materialsShown() const
Sets whether textures/material should be displayed or not.
void showNormals(bool state) override
Sets normals visibility.
bool updateTextures(const std::vector< std::string > &texture_files)
virtual bool hasTextures() const =0
Returns whether textures are available for this mesh.
void importParametersFrom(const ccGenericMesh *mesh)
Imports the parameters from another mesh.
virtual void showWired(bool state)
Sets whether mesh should be displayed as a wire or with plain facets.
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
virtual bool triNormsShown() const
Returns whether per-triangle normals are shown or not.
static CCVector3 * GetNormalsBuffer()
virtual void getTriangleNormalIndexes(unsigned triangleIndex, int &i1, int &i2, int &i3) const =0
Returns a triplet of normal indexes for a given triangle (if any)
~ccGenericMesh() override=default
Destructor.
bool m_triNormsShown
Per-triangle normals display flag.
virtual bool isShownAsWire() const
Returns whether the mesh is displayed as wired or with plain facets.
virtual bool hasPerTriangleTexCoordIndexes() const =0
Returns whether this mesh as per-triangle triplets of tex coords indexes.
virtual bool trianglePicking(unsigned triIndex, const CCVector2d &clickPos, const ccGLMatrix &trans, bool noGLTrans, const ccGenericPointCloud &vertices, const ccGLCameraParameters &camera, CCVector3d &point, CCVector3d *barycentricCoords=nullptr) const
Triangle picking (single triangle)
virtual void getTriangleTexCoordinatesIndexes(unsigned triangleIndex, int &i1, int &i2, int &i3) const =0
Returns the triplet of tex coords indexes for a given triangle.
static CCVector3 * GetVertexBuffer()
virtual const ccMaterialSet * getMaterialSet() const =0
bool m_stippling
Polygon stippling state.
virtual bool hasTriNormals() const =0
Returns whether the mesh has per-triangle normals.
virtual bool getTriangleNormals(unsigned triangleIndex, CCVector3 &Na, CCVector3 &Nb, CCVector3 &Nc) const =0
Returns a given triangle normal.
ccPointCloud * samplePoints(bool densityBased, double samplingParameter, bool withNormals, bool withRGB, bool withTexture, cloudViewer::GenericProgressCallback *pDlg=nullptr)
Samples points on a mesh.
virtual bool interpolateNormalsBC(unsigned triIndex, const CCVector3d &w, CCVector3 &N)=0
Interpolates normal(s) inside a given triangle.
bool isSerializable() const override
Returns whether object is serializable of not.
const CCVector3d & getGlobalShift() const override
Returns the shift applied to original coordinates.
virtual int getTriangleMtlIndex(unsigned triangleIndex) const =0
Returns a given triangle material indexes.
bool m_showWired
Wireframe display mode.
short minimumFileVersion_MeOnly() const override
virtual ccGenericPointCloud * getAssociatedCloud() const =0
Returns the vertices cloud.
double getGlobalScale() const override
Returns the scale applied to original coordinates.
virtual bool interpolateColors(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &C)=0
Interpolates RGB colors inside a given triangle.
void enableStippling(bool state)
Enables polygon stippling.
static unsigned * GetWireVertexIndexes()
Returns a pre-initialized array of vertex indexes for wired display.
virtual bool getVertexColorFromMaterial(unsigned triIndex, unsigned char vertIndex, ecvColor::Rgb &C, bool returnColorIfNoTexture)=0
virtual void computeInterpolationWeights(unsigned triIndex, const CCVector3 &P, CCVector3d &weights) const
Returns the (barycentric) interpolation weights for a given triangle.
virtual void getTriangleTexCoordinates(unsigned triIndex, TexCoords2D *&tx1, TexCoords2D *&tx2, TexCoords2D *&tx3) const =0
Returns per-triangle texture coordinates (pointer to)
virtual bool trianglePicking(const CCVector2d &clickPos, const ccGLCameraParameters &camera, int &nearestTriIndex, double &nearestSquareDist, CCVector3d &nearestPoint, CCVector3d *barycentricCoords=nullptr) const
Brute force triangle picking.
void setGlobalShift(const CCVector3d &shift) override
Sets shift applied to original coordinates (information storage only)
bool m_materialsShown
Texture/material display flag.
bool computePointPosition(unsigned triIndex, const CCVector2d &uv, CCVector3 &P, bool warningIfOutside=true) const
virtual void showMaterials(bool state)
Sets whether textures should be displayed or not.
virtual bool isShownAsPoints() const
Returns whether the mesh is displayed as wired or with plain facets.
void handleColorRamp(CC_DRAW_CONTEXT &context)
Handles the color ramp display.
virtual NormsIndexesTableType * getTriNormsTable() const =0
Returns per-triangle normals shared array.
virtual bool getTriangleNormals(unsigned triangleIndex, Eigen::Vector3d &Na, Eigen::Vector3d &Nb, Eigen::Vector3d &Nc) const
ccGenericMesh(QString name=QString())
Default constructor.
static ecvColor::Rgb * GetColorsBuffer()
virtual void getTexCoordinates(unsigned index, TexCoords2D *&tx) const =0
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
static bool IsCloudVerticesOfMesh(ccGenericPointCloud *cloud, ccGenericMesh **mesh=nullptr)
Helper to determine if the input cloud acts as vertices of a mesh.
void drawMeOnly(CC_DRAW_CONTEXT &context) override
Enables (OpenGL) stipple mask.
virtual bool trianglePicking(unsigned triIndex, const CCVector2d &clickPos, const ccGLCameraParameters &camera, CCVector3d &point, CCVector3d *barycentricCoords=nullptr) const
Triangle picking (single triangle)
bool m_showPoints
points display mode
virtual unsigned capacity() const =0
Returns max capacity.
virtual void refreshBB()=0
Forces bounding-box update.
virtual bool getColorFromMaterial(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &C, bool interpolateColorIfNoTexture)=0
void setGlobalScale(double scale) override
virtual bool stipplingEnabled() const
Returns whether polygon stippling is enabled or not.
virtual bool hasMaterials() const =0
bool normalsAvailable() const override
Returns whether normals are available.
virtual void showTriNorms(bool state)
Sets whether to show or not per-triangle normals.
A 3D cloud interface with associated features (color, normals, octree, etc.)
Mesh (triangle) material.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
Shifted entity interface.
A generic mesh with index-based vertex access.
RGB color structure.
Definition: ecvColorTypes.h:49
ImGuiContext * context
Definition: Window.cpp:76
Generic file read and write utility for python interface.
2D texture coordinates
OpenGL camera parameters.
Display context.
Definition: lsd.c:149