ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvDrawContext.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <CVGeom.h>
11 
12 #include <QFont>
13 #include <QImage>
14 #include <QPoint>
15 #include <QRect>
16 
17 #include "ecvColorTypes.h"
18 #include "ecvGLMatrix.h"
19 #include "ecvMaterial.h"
20 
21 class ccHObject;
22 class ccScalarField;
23 
25 struct glDrawParams {
27  bool showSF;
29  bool showColors;
31  bool showNorms;
32 };
33 
40 };
41 
43 
48 };
49 
76 };
77 
96 };
97 
100  QString viewId;
101  int viewport = 0;
102  PointCoordinateType lineWidth = 2;
103  unsigned char pointSize = 1;
106 
107  double opacity = 1.0;
111 
113  : entity(obj),
114  color(col),
115  property(PROPERTY_MODE::ECV_COLOR_PROPERTY) {}
116 
117  PROPERTY_PARAM(ccHObject* obj, double opacity)
118  : entity(obj),
119  opacity(opacity),
120  property(PROPERTY_MODE::ECV_OPACITY_PROPERTY) {}
121 
122  PROPERTY_PARAM(ccHObject* obj, unsigned char pointSize)
123  : entity(obj), property(PROPERTY_MODE::ECV_POINTSSIZE_PROPERTY) {
124  if (pointSize > 1) {
125  this->pointSize = pointSize;
126  }
127  }
128 
130  : entity(obj), property(PROPERTY_MODE::ECV_SHADING_PROPERTY) {
131  this->shadingMode = shadingMode;
132  }
133 
134  inline void setProperty(PROPERTY_MODE mode) { property = mode; }
135 
136  inline void setShadingMode(SHADING_MODE shadingMode) {
137  this->shadingMode = shadingMode;
138  }
139 
140  inline void setColor(const ecvColor::Rgb& col) {
141  color = const_cast<ecvColor::Rgb&>(col);
142  }
143 
144  inline void setPointSize(unsigned char size) { pointSize = size; }
145 
146  inline void setOpacity(double op) { opacity = op; }
147 
148  inline void setLineWith(PointCoordinateType with) { lineWidth = with; }
149 };
150 
154  float lineWidth;
156  bool valid;
158  : lineWidth(width), lineColor(color), valid(false) {}
159 
161  const CCVector3& ed,
162  float width = 2,
164  : lineSt(st),
165  lineEd(ed),
166  lineWidth(width),
167  lineColor(color),
168  valid(true) {}
169 };
170 
176  QString removeId;
177 
178  friend bool operator==(const removeInfo& first, const removeInfo& second) {
179  return (first.removeType == second.removeType &&
180  first.removeId == second.removeId)
181  ? true
182  : false;
183  }
184 };
185 
190  QString hideId;
191 
192  friend bool operator==(const hideInfo& first, const hideInfo& second) {
193  return (first.hideType == second.hideType &&
194  first.hideId == second.hideId)
195  ? true
196  : false;
197  }
198 };
199 
201  struct RotateParam {
202  double angle;
204  };
205 
207  bool isRotate = false;
208  bool applyEuler = true;
209  bool isScale = false;
210  bool isTranslate = false;
211  bool isPositionChanged = false;
212 
213  double quaternion[4];
214 
216 
219 
222 
224 
225  void setPostion(const CCVector3& pos) {
226  position = pos;
227  isPositionChanged = true;
228  }
229 
230  bool isApplyTransform() const {
231  return isRotate || isScale || isTranslate || isPositionChanged;
232  }
233 
234  void setTransformation(const ccGLMatrixd& transform,
235  bool updateTranslation = true,
236  bool useEuler = false) {
237  if (useEuler) {
238  // double phi_rad, theta_rad, psi_rad;
239  // CCVector3d t3D;
240  // transform.getParameters(phi_rad, theta_rad, psi_rad,
241  // t3D);
242  // setRotation(cloudViewer::RadiansToDegrees(psi_rad),
243  // cloudViewer::RadiansToDegrees(theta_rad),
244  // cloudViewer::RadiansToDegrees(phi_rad));
245  // if (updateTranslation)
246  // {
247  // setTranslationStart(CCVector3::fromArray(transform.getTranslationAsVec3D().u));
248  // }
249 
250  double rz, ry, rx;
251  transform.toEulerAngle(rz, ry, rx);
252  setRotation(cloudViewer::RadiansToDegrees(rz),
255  if (updateTranslation) {
256  setTranslationStart(CCVector3::fromArray(
257  transform.getTranslationAsVec3D().u));
258  }
259 
260  } else {
261  double angle_rad;
262  CCVector3d axis, trans;
263  transform.getParameters(angle_rad, axis, trans);
264  double angle_deg = cloudViewer::RadiansToDegrees(angle_rad);
265  setRotation(angle_deg, axis);
266  if (updateTranslation) {
267  setTranslationStart(CCVector3::fromArray(trans.u));
268  }
269  }
270  }
271  void setTransformation(const ccGLMatrix& transform,
272  bool updateTranslation = true,
273  bool useEuler = true) {
274  setTransformation(ccGLMatrixd(transform.data()), updateTranslation,
275  useEuler);
276  }
277 
278  void setRotation(double zAngle, double yAngle, double xAngle) {
279  isRotate = true;
280  applyEuler = true;
281  eulerZYX[0] = zAngle;
282  eulerZYX[1] = yAngle;
283  eulerZYX[2] = xAngle;
284  }
285  void setRotation(double zyxAngle[3]) {
286  setRotation(zyxAngle[0], zyxAngle[1], zyxAngle[2]);
287  }
288 
289  void setRotation(double angle, double x, double y, double z) {
290  setRotation(angle, CCVector3d(x, y, z));
291  }
292  void setRotation(double angle, const CCVector3& axis) {
293  isRotate = true;
294  applyEuler = false;
295  rotateParam.angle = angle;
296  rotateParam.rotAxis = axis;
297  }
298  void setRotation(double angle, const CCVector3d& axis) {
299  isRotate = true;
300  applyEuler = false;
301  rotateParam.angle = angle;
302  rotateParam.rotAxis = CCVector3::fromArray(axis.u);
303  }
304 
305  void setScale(const CCVector3& scale) {
306  isScale = true;
307  scaleXYZ = scale;
308  }
309  void setTranslationStart(const CCVector3& trans) {
310  isTranslate = true;
311  transVecStart = trans;
312  }
313  void setTranslationEnd(const CCVector3& trans) {
314  isTranslate = true;
315  transVecEnd = trans;
316  }
317 };
318 
320  bool display3D = false;
321  double textScale = 1.0;
322  double opacity = 1.0;
323  CCVector3d textPos = CCVector3d(0.0, 0.0, 0.0);
324  QString text = "";
325  QFont font = QFont();
326 };
327 
328 // Drawing flags (type: short)
330  CC_DRAW_2D = 0x0001,
331  CC_DRAW_3D = 0x0002,
336  CC_SKIP_ALL = 0x0030, // = CC_SKIP_UNSELECTED | CC_SKIP_SELECTED
337  CC_ENTITY_PICKING = 0x0040, // formerly named CC_DRAW_ENTITY_NAMES
338  // CC_FREE_FLAG = 0x0080, // UNUSED (formerly
339  // CC_DRAW_POINT_NAMES)
340  // CC_FREE_FLAG = 0x0100, // UNUSED (formerly
341  // CC_DRAW_TRI_NAMES)
342  CC_FAST_ENTITY_PICKING = 0x0200, // formerly named CC_DRAW_FAST_NAMES_ONLY
343  // UNUSED (formerly CC_DRAW_ANY_NAMES = CC_DRAW_ENTITY_NAMES |
344  // CC_DRAW_POINT_NAMES | CC_DRAW_TRI_NAMES) CC_FREE_FLAG = 0x03C0,
346  CC_VIRTUAL_TRANS_ENABLED = 0x0800
347 };
348 
349 // Drawing flags testing macros (see ccDrawableObject)
350 #define MACRO_Draw2D(context) (context.drawingFlags & CC_DRAW_2D)
351 #define MACRO_Draw3D(context) (context.drawingFlags & CC_DRAW_3D)
352 #define MACRO_EntityPicking(context) (context.drawingFlags & CC_ENTITY_PICKING)
353 #define MACRO_FastEntityPicking(context) \
354  (context.drawingFlags & CC_FAST_ENTITY_PICKING)
355 #define MACRO_SkipUnselected(context) \
356  (context.drawingFlags & CC_SKIP_UNSELECTED)
357 #define MACRO_SkipSelected(context) (context.drawingFlags & CC_SKIP_SELECTED)
358 #define MACRO_LightIsEnabled(context) (context.drawingFlags & CC_LIGHT_ENABLED)
359 #define MACRO_Foreground(context) (context.drawingFlags & CC_DRAW_FOREGROUND)
360 #define MACRO_LODActivated(context) (context.drawingFlags & CC_LOD_ACTIVATED)
361 #define MACRO_VirtualTransEnabled(context) \
362  (context.drawingFlags & CC_VIRTUAL_TRANS_ENABLED)
363 
372 
373  QString viewID;
376  float normalScale;
377 
378  float opacity;
379 
380  bool visible;
381  unsigned char defaultLineWidth;
382  unsigned char currentLineWidth;
383  unsigned char defaultPointSize;
387 
388  QString removeViewID;
390 
393 
395  int glW;
397  int glH;
400 
402  float renderZoom;
403 
406 
413 
416 
425 
427 
432 
436 
442  unsigned char currentLODLevel;
447 
452 
455 
457  bool useVBOs;
458 
463 
466 
468  unsigned labelOpacity;
469 
471  unsigned stereoPassIndex;
472 
475 
476  // Default constructor
478  : drawingFlags(0),
479  forceRedraw(true),
480  visFiltering(false),
481  viewID("unnamed"),
482  defaultViewPort(0),
483  normalDensity(100),
484  normalScale(0.02f),
485  opacity(1.0),
486  visible(true),
487  defaultLineWidth(2),
489  defaultPointSize(1),
491  removeViewID("unnamed"),
493  clearDepthLayer(true),
494  clearColorLayer(true),
495  glW(0),
496  glH(0),
497  devicePixelRatio(1.0f),
498  renderZoom(1.0f),
499  defaultMat(new ccMaterial("default")),
514  decimateCloudOnMove(true),
515  minLODPointCount(10000000),
516  currentLODLevel(0),
517  moreLODPointsAvailable(false),
519  decimateMeshOnMove(true),
520  minLODTriangleCount(2500000),
521  sfColorScaleToDisplay(nullptr),
522  useVBOs(true),
523  labelMarkerSize(5),
526  labelOpacity(100),
527  stereoPassIndex(0),
528  drawRoundedPoints(false) {}
529 };
530 
532 
534 public:
535  /*for general*/
538  QString viewID;
539  int viewport = 0;
541 
543 
544  int fontSize = 10;
545 
546  /*for image*/
547  QImage image;
548  double opacity = 1.0;
549 
550  /*for text*/
551  QString text;
552 
553  /*for rectangle*/
554  bool filled = true;
555  QRect rect;
556 
557  /*for 2D line or triangle*/
558  QPoint p1;
559  QPoint p2;
560  QPoint p3;
561  QPoint p4 = QPoint(-1, -1);
562 
563  /*for circle, sphere or mark point*/
564  float radius;
567  bool handleEnabled = false;
568 
569  /*for 3D line*/
571 
572  // Default constructor
573  WIDGETS_PARAMETER(WIDGETS_TYPE t, QString id = "id", int port = 0)
574  : type(t), viewID(id), viewport(port) {
575  context.viewID = viewID;
576  }
577 
579  WIDGETS_TYPE t,
580  QString id = "id",
581  int port = 0)
582  : entity(obj), type(t), viewID(id), viewport(port) {
583  context.viewID = viewID;
584  }
585 
586  void setLineWidget(const LineWidget& line) { lineWidget = line; }
587 };
Vector3Tpl< double > CCVector3d
Double 3D Vector.
Definition: CVGeom.h:804
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
#define CV_DB_LIB_API
Definition: CV_db.h:15
int width
int size
char type
math::float4 color
math::float3 position
Type u[3]
Definition: CVGeom.h:139
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
Definition: CVGeom.h:268
Vector3Tpl< T > getTranslationAsVec3D() const
Returns a copy of the translation as a CCVector3.
T * data()
Returns a pointer to internal data.
void toEulerAngle(T &rz, T &ry, T &rx) const
Returns equivalent parameters: 3 rotation angles.
void getParameters(T &alpha_rad, Vector3Tpl< T > &axis3D, Vector3Tpl< T > &t3D) const
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
Double version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:56
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
Mesh (triangle) material.
Definition: ecvMaterial.h:28
QSharedPointer< ccMaterial > Shared
Shared type.
Definition: ecvMaterial.h:33
A scalar field associated to display-related parameters.
RGB color structure.
Definition: ecvColorTypes.h:49
RGBA color structure.
MESH_RENDERING_MODE
@ ECV_POINTS_MODE
@ ECV_SURFACE_MODE
@ ECV_WIREFRAME_MODE
PROPERTY_MODE
@ ECV_COLOR_PROPERTY
@ ECV_SHADING_PROPERTY
@ ECV_POINTSSIZE_PROPERTY
@ ECV_OPACITY_PROPERTY
@ ECV_LINEWITH_PROPERTY
SHADING_MODE
@ ECV_SHADING_PHONG
@ ECV_SHADING_FLAT
@ ECV_SHADING_GOURAUD
CC_DRAWING_FLAGS
@ CC_DRAW_2D
@ CC_LOD_ACTIVATED
@ CC_DRAW_FOREGROUND
@ CC_FAST_ENTITY_PICKING
@ CC_LIGHT_ENABLED
@ CC_VIRTUAL_TRANS_ENABLED
@ CC_SKIP_SELECTED
@ CC_DRAW_3D
@ CC_SKIP_UNSELECTED
@ CC_ENTITY_PICKING
@ CC_SKIP_ALL
WIDGETS_TYPE
@ WIDGET_RECTANGLE_2D
@ WIDGET_CAPTION
@ WIDGET_IMAGE
@ WIDGET_TRIANGLE_2D
@ WIDGET_POINTS_2D
@ WIDGET_COORDINATE
@ WIDGET_LINE_3D
@ WIDGET_SPHERE
@ WIDGET_T2D
@ WIDGET_SCALAR_BAR
@ WIDGET_T3D
@ WIDGET_POLYLINE
@ WIDGET_POLYLINE_2D
@ WIDGET_BBOX
@ WIDGET_POLYGONMESH
@ WIDGET_CIRCLE_2D
@ WIDGET_LINE_2D
ENTITY_TYPE
@ ECV_POLYGON
@ ECV_LINES_2D
@ ECV_SENSOR
@ ECV_TEXT3D
@ ECV_POLYLINE_2D
@ ECV_KDTREE
@ ECV_FACET
@ ECV_CAPTION
@ ECV_IMAGE
@ ECV_LINES_3D
@ ECV_TEXT2D
@ ECV_TRIANGLE_2D
@ ECV_MESH
@ ECV_ALL
@ ECV_NONE
@ ECV_OCTREE
@ ECV_2DLABLE
@ ECV_HIERARCHY_OBJECT
@ ECV_SHAPE
@ ECV_CIRCLE_2D
@ ECV_SCALAR_BAR
@ ECV_RECTANGLE_2D
@ ECV_2DLABLE_VIEWPORT
@ ECV_MARK_POINT
@ ECV_POINT_CLOUD
ImGuiContext * context
Definition: Window.cpp:76
float RadiansToDegrees(int radians)
Convert radians to degrees.
Definition: CVMath.h:71
Colors namespace.
Definition: ecvColorTypes.h:32
constexpr Rgbub defaultColor(MAX, MAX, MAX)
constexpr Rgbub defaultLabelMarkerColor(MAX, 0, MAX)
constexpr Rgbf defaultViewBkgColor(10/255.0f, 102/255.0f, 151/255.0f)
constexpr Rgb red(MAX, 0, 0)
constexpr Rgb lightGrey(static_cast< ColorCompType >(MAX *0.8), static_cast< ColorCompType >(MAX *0.8), static_cast< ColorCompType >(MAX *0.8))
constexpr Rgb green(0, MAX, 0)
constexpr Rgb yellow(MAX, MAX, 0)
constexpr Rgbub defaultBkgColor(135, 206, 235)
constexpr Rgbub defaultLabelBkgColor(MAX, MAX, MAX)
CCVector3 lineEd
LineWidget(float width=2.0f, const ecvColor::Rgb &color=ecvColor::red)
CCVector3 lineSt
LineWidget(const CCVector3 &st, const CCVector3 &ed, float width=2, const ecvColor::Rgb &color=ecvColor::red)
ecvColor::Rgb lineColor
void setColor(const ecvColor::Rgb &col)
void setShadingMode(SHADING_MODE shadingMode)
ccHObject * entity
PROPERTY_PARAM(ccHObject *obj, const ecvColor::Rgb &col)
void setPointSize(unsigned char size)
PROPERTY_PARAM(ccHObject *obj, double opacity)
PROPERTY_PARAM(ccHObject *obj, SHADING_MODE shadingMode)
ENTITY_TYPE entityType
ecvColor::Rgb color
PROPERTY_MODE property
void setOpacity(double op)
SHADING_MODE shadingMode
void setLineWith(PointCoordinateType with)
void setProperty(PROPERTY_MODE mode)
QString viewId
Display scalar field (prioritary on colors)
PROPERTY_PARAM(ccHObject *obj, unsigned char pointSize)
void setScale(const CCVector3 &scale)
void setTranslationEnd(const CCVector3 &trans)
bool isApplyTransform() const
void setRotation(double angle, const CCVector3 &axis)
void setTranslationStart(const CCVector3 &trans)
void setTransformation(const ccGLMatrix &transform, bool updateTranslation=true, bool useEuler=true)
CCVector3 transVecStart
void setRotation(double zyxAngle[3])
void setTransformation(const ccGLMatrixd &transform, bool updateTranslation=true, bool useEuler=false)
void setRotation(double angle, const CCVector3d &axis)
RotateParam rotateParam
void setRotation(double zAngle, double yAngle, double xAngle)
CCVector3 position
CCVector3d eulerZYX
CCVector3 transVecEnd
void setRotation(double angle, double x, double y, double z)
CCVector3 scaleXYZ
the x y z scale
void setPostion(const CCVector3 &pos)
LineWidget lineWidget
WIDGETS_PARAMETER(ccHObject *obj, WIDGETS_TYPE t, QString id="id", int port=0)
ecvColor::Rgbaf color
WIDGETS_PARAMETER(WIDGETS_TYPE t, QString id="id", int port=0)
CC_DRAW_CONTEXT context
WIDGETS_TYPE type
ccHObject * entity
void setLineWidget(const LineWidget &line)
Display context.
ecvColor::Rgbub pointsDefaultCol
Default point color.
ecvColor::Rgbub bbDefaultCol
Default bounding-box color.
float renderZoom
Current zoom (screen to file rendering mode)
float devicePixelRatio
Device pixel ratio (general 1, 2 on HD displays)
float labelMarkerSize
Label marker size (radius)
ENTITY_TYPE hideShowEntityType
int drawingFlags
Drawing options (see below)
ecvColor::Rgbaf defaultMeshFrontDiff
Default color for mesh (front side)
bool decimateMeshOnMove
Whether to decimate big meshes when rotating the camera.
bool higherLODLevelsAvailable
Wheter higher levels are available or not.
glDrawParams drawParam
unsigned labelOpacity
Label background opacity.
unsigned minLODPointCount
Minimum number of points for activating LOD display.
ecvColor::Rgbub labelDefaultBkgCol
Default label background color.
int glH
GL screen height.
ecvColor::Rgb defaultPolylineColor
Default color for polyline.
ecvColor::Rgbub backgroundCol2
unsigned char defaultLineWidth
bool moreLODPointsAvailable
Wheter more points are available or not at the current level.
unsigned dispNumberPrecision
Numerical precision (for displaying text)
ecvTextParam textParam
ecvColor::Rgbub labelDefaultMarkerCol
Default label marker color.
ecvColor::Rgbub backgroundCol
unsigned char currentLODLevel
Current level for LOD display.
float labelMarkerTextShift_pix
Shift for 3D label marker display (around the marker, in pixels)
ccMaterial::Shared defaultMat
Default material.
int glW
GL screen widthecvColor.
ecvColor::Rgb defaultMeshColor
Default color for mesh.
unsigned char currentLineWidth
unsigned minLODTriangleCount
Minimum number of triangles for activating LOD display.
ccScalarField * sfColorScaleToDisplay
Currently displayed color scale (the corresponding scalar field in fact)
ENTITY_TYPE removeEntityType
ecvColor::Rgbub textDefaultCol
Default text color.
MESH_RENDERING_MODE meshRenderingMode
TransformInfo transformInfo
unsigned stereoPassIndex
Stereo pass index.
bool useVBOs
Use VBOs for faster display.
ecvColor::Rgbaf defaultMeshBackDiff
Default color for mesh (back side)
bool decimateCloudOnMove
Whether to decimate big clouds when updating the 3D view.
unsigned char defaultPointSize
ecvColor::Rgbub pointsCurrentCol
Current point color.
ecvColor::Rgbf viewDefaultBkgCol
bool drawRoundedPoints
Whether to draw rounded points (instead of sqaures)
Display parameters of a 3D entity.
bool showColors
Display colors.
bool showNorms
Display normals.
bool showSF
Display scalar field (prioritary on colors)
ENTITY_TYPE hideType
Hide type.
QString hideId
Hide viewId.
friend bool operator==(const hideInfo &first, const hideInfo &second)
to be removed structure
ENTITY_TYPE removeType
Remove type.
QString removeId
Remove viewId.
friend bool operator==(const removeInfo &first, const removeInfo &second)