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 
46  virtual ccGenericPointCloud* getAssociatedCloud() const = 0;
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 
67  virtual TextureCoordsContainer* getTexCoordinatesTable() const = 0;
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 
125  virtual NormsIndexesTableType* getTriNormsTable() const = 0;
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 
210  ccPointCloud* samplePoints(
211  bool densityBased,
212  double samplingParameter,
213  bool withNormals,
214  bool withRGB,
215  bool withTexture,
216  cloudViewer::GenericProgressCallback* pDlg = nullptr);
217 
219 
221  void importParametersFrom(const ccGenericMesh* mesh);
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 
246  static bool IsCloudVerticesOfMesh(ccGenericPointCloud* cloud,
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
271  static CCVector3* GetVertexBuffer();
272  static CCVector3* GetNormalsBuffer();
273  static ecvColor::Rgb* GetColorsBuffer();
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
295  void drawMeOnly(CC_DRAW_CONTEXT& context) override;
296 
298  void handleColorRamp(CC_DRAW_CONTEXT& context);
299 
302 
305 
308 
311 
314 };
cloudViewer
Generic file read and write utility for python interface.
Definition: CloudViewerConfig.cpp:12
ccGenericMesh::materialsShown
virtual bool materialsShown() const
Sets whether textures/material should be displayed or not.
Definition: ecvGenericMesh.h:198
TexCoords2D
2D texture coordinates
Definition: ecvAdvancedTypes.h:138
ccDrawableObject::showNormals
virtual void showNormals(bool state)
Sets normals visibility.
Definition: ecvDrawableObject.h:93
ccGenericMesh::m_stippling
bool m_stippling
Polygon stippling state.
Definition: ecvGenericMesh.h:313
ccEntityAction::interpolateColors
bool interpolateColors(const ccHObject::Container &selectedEntities, QWidget *parent)
Interpolate colors from on entity and transfer them to another one.
Definition: ecvEntityAction.cpp:292
ccHObject::toFile_MeOnly
virtual bool toFile_MeOnly(QFile &out, short dataVersion) const
Save own object data.
Definition: ecvHObject.cpp:1302
ccHObject::minimumFileVersion_MeOnly
virtual short minimumFileVersion_MeOnly() const
Definition: ecvHObject.cpp:1364
ccGenericMesh::showTriNorms
virtual void showTriNorms(bool state)
Sets whether to show or not per-triangle normals.
Definition: ecvGenericMesh.h:195
ccShiftedObject::setGlobalScale
virtual void setGlobalScale(double scale)
Definition: ecvShiftedObject.cpp:33
ccGenericMesh::stipplingEnabled
virtual bool stipplingEnabled() const
Returns whether polygon stippling is enabled or not.
Definition: ecvGenericMesh.h:204
ecvBBox.h
ccPointCloud
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Definition: ecvPointCloud.h:146
cloudViewer::GenericProgressCallback
Definition: GenericProgressCallback.h:20
ccGLCameraParameters
OpenGL camera parameters.
Definition: ecvGenericDisplayTools.h:554
GenericIndexedMesh.h
ccDrawableObject::hasNormals
virtual bool hasNormals() const
Returns whether normals are enabled or not.
Definition: ecvDrawableObject.h:89
ccGenericMesh::isShownAsPoints
virtual bool isShownAsPoints() const
Returns whether the mesh is displayed as wired or with plain facets.
Definition: ecvGenericMesh.h:185
ccGenericMesh::getTriangleNormals
virtual bool getTriangleNormals(unsigned triangleIndex, Eigen::Vector3d &Na, Eigen::Vector3d &Nb, Eigen::Vector3d &Nc) const
Definition: ecvGenericMesh.h:117
NormsIndexesTableType
Array of compressed 3D normals (single index)
Definition: ecvAdvancedTypes.h:21
Vector2Tpl< double >
context
ImGuiContext * context
Definition: Window.cpp:76
ccShiftedObject::getGlobalShift
virtual const CCVector3d & getGlobalShift() const
Returns the shift applied to original coordinates.
Definition: ecvShiftedObject.h:46
ccGenericPointCloud
A 3D cloud interface with associated features (color, normals, octree, etc.)
Definition: ecvGenericPointCloud.h:45
Vector3Tpl< PointCoordinateType >
ccGenericMesh::isShownAsWire
virtual bool isShownAsWire() const
Returns whether the mesh is displayed as wired or with plain facets.
Definition: ecvGenericMesh.h:179
ccGenericMesh::m_triNormsShown
bool m_triNormsShown
Per-triangle normals display flag.
Definition: ecvGenericMesh.h:301
ccGenericMesh::showPoints
virtual void showPoints(bool state)
Definition: ecvGenericMesh.h:189
ccHObject::fromFile_MeOnly
virtual bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap)
Loads own object data.
Definition: ecvHObject.cpp:1371
ccGenericMesh
Generic mesh interface.
Definition: ecvGenericMesh.h:28
ecvAdvancedTypes.h
ecvShiftedObject.h
TextureCoordsContainer
Array of 2D texture coordinates.
Definition: ecvAdvancedTypes.h:151
ccShiftedObject
Shifted entity interface.
Definition: ecvShiftedObject.h:18
cloudViewer::GenericIndexedMesh
A generic mesh with index-based vertex access.
Definition: GenericIndexedMesh.h:37
ccGenericMesh::m_materialsShown
bool m_materialsShown
Texture/material display flag.
Definition: ecvGenericMesh.h:304
ccGLMatrix
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
ccGenericMesh::isSerializable
bool isSerializable() const override
Returns whether object is serializable of not.
Definition: ecvGenericMesh.h:43
ccGenericMesh::showMaterials
virtual void showMaterials(bool state)
Sets whether textures should be displayed or not.
Definition: ecvGenericMesh.h:201
uv
math::float2 uv
Definition: PointCloudBuffers.cpp:51
ecvColor::RgbTpl
RGB color structure.
Definition: ecvColorTypes.h:49
ccShiftedObject::getGlobalScale
virtual double getGlobalScale() const
Returns the scale applied to original coordinates.
Definition: ecvShiftedObject.h:53
ccGenericMesh::normalsAvailable
bool normalsAvailable() const override
Returns whether normals are available.
Definition: ecvGenericMesh.h:256
ccShiftedObject::setGlobalShift
virtual void setGlobalShift(double x, double y, double z)
Sets shift applied to original coordinates (information storage only)
Definition: ecvShiftedObject.h:33
ccMaterialSet
Mesh (triangle) material.
Definition: ecvMaterialSet.h:16
ccGenericMesh::getTriangleNormals
virtual bool getTriangleNormals(unsigned triangleIndex, double Na[3], double Nb[3], double Nc[3]) const
Definition: ecvGenericMesh.h:111
ccGenericMesh::m_showPoints
bool m_showPoints
points display mode
Definition: ecvGenericMesh.h:310
ccGenericMesh::m_showWired
bool m_showWired
Wireframe display mode.
Definition: ecvGenericMesh.h:307
CV_DB_LIB_API
#define CV_DB_LIB_API
Definition: CV_db.h:15
ccGLDrawContext
Display context.
Definition: ecvDrawContext.h:365
ccGenericMesh::triNormsShown
virtual bool triNormsShown() const
Returns whether per-triangle normals are shown or not.
Definition: ecvGenericMesh.h:192
ccGenericMesh::showWired
virtual void showWired(bool state)
Sets whether mesh should be displayed as a wire or with plain facets.
Definition: ecvGenericMesh.h:182
ccHObject::drawMeOnly
virtual void drawMeOnly(CC_DRAW_CONTEXT &context)
Draws the entity only (not its children)
Definition: ecvHObject.h:655
ccGenericMesh::enableStippling
void enableStippling(bool state)
Enables polygon stippling.
Definition: ecvGenericMesh.h:207
name
std::string name
Definition: FileIOFactory.cpp:129