ccGlobalShiftManager.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  4. //# #
  5. //# This program is free software; you can redistribute it and/or modify #
  6. //# it under the terms of the GNU General Public License as published by #
  7. //# the Free Software Foundation; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  15. //# #
  16. //##########################################################################
  17. #ifndef CC_GLOBAL_SHIFT_MANAGER_HEADER
  18. #define CC_GLOBAL_SHIFT_MANAGER_HEADER
  19. //CCCoreLib
  20. #include <CCGeom.h>
  21. //local
  22. #include "qCC_io.h"
  23. //Qt
  24. #include <QString>
  25. //STL
  26. #include <vector>
  27. class ccHObject;
  28. //! Helper class to handle big coordinates shift/scale (typically while loading entities)
  29. class QCC_IO_LIB_API ccGlobalShiftManager
  30. {
  31. public:
  32. //! Strategy to handle coordinates shift/scale
  33. enum Mode { NO_DIALOG, NO_DIALOG_AUTO_SHIFT, DIALOG_IF_NECESSARY, ALWAYS_DISPLAY_DIALOG };
  34. //! Handles coordinates shift/scale given the first 3D point and current related parameters
  35. static bool Handle( const CCVector3d& P,
  36. double diagonal,
  37. Mode mode,
  38. bool useInputCoordinatesShiftIfPossible,
  39. CCVector3d& coordinatesShift,
  40. bool* _preserveCoordinateShift = nullptr,
  41. double* _coordinatesScale = nullptr,
  42. bool* _applyAll = nullptr);
  43. //! Returns whether a particular point (coordinates) is too big or not
  44. static bool NeedShift(const CCVector3d& P);
  45. //! Returns whether a particular point coordinate is too big or not
  46. static bool NeedShift(double d);
  47. //! Returns whether a particular dimension (e.g. diagonal) is too big or not
  48. static bool NeedRescale(double d);
  49. //! Suggests a shift for a given point expressed in global coordinate space
  50. static CCVector3d BestShift(const CCVector3d& P);
  51. //! Suggests a scale for a given dimension (e.g. diagonal) in global coordinate space
  52. static double BestScale(double d);
  53. //! Returns the max coordinate (absolute) value
  54. static double MaxCoordinateAbsValue() { return MAX_COORDINATE_ABS_VALUE; }
  55. //! Sets the max coordinate (absolute) value
  56. static void SetMaxCoordinateAbsValue(double value) { MAX_COORDINATE_ABS_VALUE = std::max(value, 1.0); }
  57. //! Returns max bounding-box diagonal
  58. static double MaxBoundgBoxDiagonal() { return MAX_DIAGONAL_LENGTH; }
  59. //! Sets the max bounding-box diagonal
  60. static void SetMaxBoundgBoxDiagonal(double value) { MAX_DIAGONAL_LENGTH = value; }
  61. //! Adds a new shift / scale couple
  62. static void StoreShift(const CCVector3d& shift, double scale, bool preserve = true);
  63. public: //Shift and scale info
  64. //! Shift and scale info
  65. struct ShiftInfo
  66. {
  67. CCVector3d shift;
  68. double scale;
  69. QString name;
  70. bool preserve;
  71. //! Default constructor
  72. ShiftInfo(QString str = QString("unnamed")) : shift(0, 0, 0), scale(1.0), name(str), preserve(true) {}
  73. //! Constructor from a vector and a scale value
  74. ShiftInfo(QString str, const CCVector3d& T, double s = 1.0) : shift(T), scale(s), name(str), preserve(true) {}
  75. };
  76. //! Returns the default and last input shift/scale entries
  77. const static std::vector<ShiftInfo>& GetLast();
  78. //! Tries to load ShiftInfo data from a (text) file
  79. /** \param[in] filename filename
  80. \param[out] infos read information
  81. \return success
  82. **/
  83. static bool LoadInfoFromFile(QString filename, std::vector<ShiftInfo>& infos);
  84. protected:
  85. // Max acceptable coordinate value
  86. static double MAX_COORDINATE_ABS_VALUE;
  87. // Max acceptable diagonal length
  88. static double MAX_DIAGONAL_LENGTH;
  89. };
  90. #endif