ccViewportParameters.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #pragma once
  2. //##########################################################################
  3. //# #
  4. //# CLOUDCOMPARE #
  5. //# #
  6. //# This program is free software; you can redistribute it and/or modify #
  7. //# it under the terms of the GNU General Public License as published by #
  8. //# the Free Software Foundation; version 2 or later of the License. #
  9. //# #
  10. //# This program is distributed in the hope that it will be useful, #
  11. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  12. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  13. //# GNU General Public License for more details. #
  14. //# #
  15. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  16. //# #
  17. //##########################################################################
  18. //Local
  19. #include "ccSerializableObject.h"
  20. #include "ccGLMatrix.h"
  21. //CCCoreLib
  22. #include <CCGeom.h>
  23. class QRect;
  24. //! Standard parameters for GL displays/viewports
  25. class QCC_DB_LIB_API ccViewportParameters : public ccSerializableObject
  26. {
  27. public: //functions
  28. //! Default constructor
  29. ccViewportParameters();
  30. //! Copy constructor
  31. ccViewportParameters(const ccViewportParameters& params);
  32. //inherited from ccSerializableObject
  33. bool isSerializable() const override { return true; }
  34. bool toFile(QFile& out, short dataVersion) const override;
  35. bool fromFile(QFile& in, short dataVersion, int flags, LoadedIDMap& oldToNewIDMap) override;
  36. short minimumFileVersion() const override;
  37. //! Sets the pivot point (for object-centered view mode)
  38. void setPivotPoint(const CCVector3d& P, bool autoUpdateFocal);
  39. //! Returns the pivot point (for object-centered view mode)
  40. const CCVector3d& getPivotPoint() const { return pivotPoint; }
  41. //! Sets the camera center
  42. //* _
  43. void setCameraCenter(const CCVector3d& C, bool autoUpdateFocal);
  44. //! Returns the camera center
  45. const CCVector3d& getCameraCenter() const { return cameraCenter; }
  46. //! Sets the 'focal' distance
  47. /** \warning changes the camera center position in object-centered view mode
  48. **/
  49. void setFocalDistance(double distance);
  50. //! Computes the 'focal' distance
  51. double getFocalDistance() const { return focalDistance; }
  52. //! Computes the view matrix
  53. ccGLMatrixd computeViewMatrix() const;
  54. //! Computes the scale matrix
  55. ccGLMatrixd computeScaleMatrix(const QRect& glViewport) const;
  56. //! Returns the viewing direction
  57. /** This is the direction normal to the screen
  58. (pointing 'forward') in the world coordinate system.
  59. **/
  60. CCVector3d getViewDir() const;
  61. //! Returns the up direction
  62. /** This is the vertical direction of the screen
  63. (pointing 'upward') in the world coordinate system.
  64. **/
  65. CCVector3d getUpDir() const;
  66. //! Returns the view rotation 'center'
  67. /** The rotation center is defined as:
  68. - the pivot point in object-centered view mode
  69. - the camera center in viewer-centered view mode
  70. **/
  71. const CCVector3d& getRotationCenter() const;
  72. //! Computes the ratio 'distance to half width' (based on the current FOV)
  73. /** Half width = ratio * distance = tan(fov / 2) * distance
  74. **/
  75. double computeDistanceToHalfWidthRatio() const;
  76. //! Computes the ratio 'distance to width' (based on the current FOV)
  77. /** Width = ratio * distance = (2 * tan(fov / 2)) * distance
  78. **/
  79. double computeDistanceToWidthRatio() const;
  80. //! Computes the object 'width' at the 'focal' distance
  81. double computeWidthAtFocalDist() const;
  82. //! Computes the pixel size at the 'focal' distance
  83. double computePixelSize(int glWidth) const;
  84. //! Logs the viewport parameters
  85. void log() const;
  86. public: //variables
  87. //! Visualization matrix (rotation only)
  88. ccGLMatrixd viewMat;
  89. //! Point size
  90. float defaultPointSize;
  91. //! Line width
  92. float defaultLineWidth;
  93. //! Perspective view state
  94. bool perspectiveView;
  95. //! Whether view is centered on displayed scene (true) or on the user eye (false)
  96. /** Always true for ortho. mode.
  97. **/
  98. bool objectCenteredView;
  99. //! Theoretical perspective 'zNear' relative position
  100. double zNearCoef;
  101. //! Depth of the near clipping plane (if any)
  102. double nearClippingDepth;
  103. //! Depth of the far clipping plane (if any)
  104. double farClippingDepth;
  105. //! Current zNear value
  106. double zNear;
  107. //! Current zFar value
  108. double zFar;
  109. //! Camera F.O.V. (field of view) in degrees
  110. float fov_deg;
  111. //! Camera aspect ratio
  112. float cameraAspectRatio;
  113. protected:
  114. //! Focal distance
  115. double focalDistance;
  116. //! Rotation pivot point (for object-centered view modes)
  117. CCVector3d pivotPoint;
  118. //! Camera center
  119. CCVector3d cameraCenter;
  120. };