ccShiftedObject.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 "ccHObject.h"
  20. //! Shifted entity interface
  21. /** Shifted entities are entities which coordinates can be
  22. (optionally) shifted so as to reduce their amplitude and
  23. therefore display or accuracy issues.
  24. **/
  25. class QCC_DB_LIB_API ccShiftedObject : public ccHObject
  26. {
  27. public:
  28. //! Default constructor
  29. /** \param name cloud name (optional)
  30. \param uniqueID unique ID (handle with care)
  31. **/
  32. ccShiftedObject(QString name = QString(), unsigned uniqueID = ccUniqueIDGenerator::InvalidUniqueID);
  33. //! Copy constructor
  34. /** \param s shifted object to copy
  35. **/
  36. ccShiftedObject(const ccShiftedObject& s) = default;
  37. //! Copies the Global Shift and Scale from another entity
  38. /** \param s shifted entity to copy information from
  39. **/
  40. void copyGlobalShiftAndScale(const ccShiftedObject& s);
  41. //! Sets shift applied to original coordinates (information storage only)
  42. /** Such a shift can typically be applied at loading time.
  43. **/
  44. virtual inline void setGlobalShift(double x, double y, double z) { return setGlobalShift(CCVector3d(x, y, z)); }
  45. //! Sets shift applied to original coordinates (information storage only)
  46. /** Such a shift can typically be applied at loading time.
  47. Original coordinates are equal to '(P/scale - shift)'
  48. **/
  49. virtual void setGlobalShift(const CCVector3d& shift);
  50. //! Returns the shift applied to original coordinates
  51. /** See ccGenericPointCloud::setOriginalShift
  52. **/
  53. virtual const CCVector3d& getGlobalShift() const { return m_globalShift; }
  54. //! Sets the scale applied to original coordinates (information storage only)
  55. virtual void setGlobalScale(double scale);
  56. //! Returns the scale applied to original coordinates
  57. virtual double getGlobalScale() const { return m_globalScale; }
  58. //! Returns whether the cloud is shifted or not
  59. inline bool isShifted() const
  60. {
  61. const CCVector3d& globalShift = getGlobalShift();
  62. return ( globalShift.x != 0
  63. || globalShift.y != 0
  64. || globalShift.z != 0
  65. || getGlobalScale() != 1.0 );
  66. }
  67. //! Returns the point back-projected into the original coordinates system
  68. template<typename T> inline CCVector3d toGlobal3d(const Vector3Tpl<T>& Plocal) const
  69. {
  70. // Pglobal = Plocal/scale - shift
  71. return Plocal.toDouble() / getGlobalScale() - getGlobalShift();
  72. }
  73. //! Returns the point projected into the local (shifted) coordinates system
  74. template<typename T> inline CCVector3d toLocal3d(const Vector3Tpl<T>& Pglobal) const
  75. {
  76. // Plocal = (Pglobal + shift) * scale
  77. return (Pglobal.toDouble() + getGlobalShift()) * getGlobalScale();
  78. }
  79. //! Returns the point projected into the local (shifted) coordinates system
  80. template<typename T> inline CCVector3 toLocal3pc(const Vector3Tpl<T>& Pglobal) const
  81. {
  82. CCVector3d Plocal = Pglobal.toDouble() * getGlobalScale() + getGlobalShift();
  83. return Plocal.toPC();
  84. }
  85. //inherited from ccHObject
  86. bool getOwnGlobalBB(CCVector3d& minCorner, CCVector3d& maxCorner) override;
  87. GlobalBoundingBox getOwnGlobalBB(bool withGLFeatures = false) override;
  88. protected:
  89. //! Serialization helper (output)
  90. bool saveShiftInfoToFile(QFile& out) const;
  91. //! Serialization helper (input)
  92. bool loadShiftInfoFromFile(QFile& in);
  93. //! Global shift (typically applied at loading time)
  94. CCVector3d m_globalShift;
  95. //! Global scale (typically applied at loading time)
  96. double m_globalScale;
  97. };