ccImage.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_IMAGE_HEADER
  18. #define CC_IMAGE_HEADER
  19. //Local
  20. #include "ccHObject.h"
  21. //Qt
  22. #include <QImage>
  23. class ccCameraSensor;
  24. //! Generic image
  25. class QCC_DB_LIB_API ccImage : public ccHObject
  26. {
  27. public:
  28. //! Default constructor
  29. ccImage();
  30. //! Constructor from QImage
  31. ccImage(const QImage& image, const QString& name = QString("unknown"));
  32. //! Copy constructor
  33. ccImage(const ccImage& image, bool keepSensorLink = true);
  34. //inherited methods (ccHObject)
  35. virtual bool isSerializable() const override { return true; }
  36. //! Returns unique class ID
  37. virtual CC_CLASS_ENUM getClassID() const override { return CC_TYPES::IMAGE; }
  38. //! Loads image from file
  39. /** \param filename image filename
  40. \param error a human readable description of what went wrong (if method fails)
  41. \return success
  42. **/
  43. bool load(const QString& filename, QString& error);
  44. //! Returns image data
  45. inline QImage& data() { return m_image; }
  46. //! Returns image data (const version)
  47. inline const QImage& data() const { return m_image; }
  48. //! Sets image data
  49. void setData(const QImage& image);
  50. //! Returns image width
  51. inline unsigned getW() const { return m_width; }
  52. //! Returns image height
  53. inline unsigned getH() const { return m_height; }
  54. //! Sets image texture transparency
  55. void setAlpha(float value);
  56. //! Returns image texture transparency
  57. inline float getAlpha() const { return m_texAlpha; }
  58. //! Manually sets aspect ratio
  59. void setAspectRatio(float ar) { m_aspectRatio = ar; }
  60. //! Returns aspect ratio
  61. inline float getAspectRatio() const { return m_aspectRatio; }
  62. //! Sets associated sensor
  63. void setAssociatedSensor(ccCameraSensor* sensor);
  64. //! Returns associated sensor
  65. ccCameraSensor* getAssociatedSensor() { return m_associatedSensor; }
  66. //! Returns associated sensor (const version)
  67. const ccCameraSensor* getAssociatedSensor() const { return m_associatedSensor; }
  68. //inherited from ccHObject
  69. virtual ccBBox getOwnFitBB(ccGLMatrix& trans) override;
  70. //! Compute the displayed image size
  71. QSizeF computeDisplayedSize(int glWidth, int glHeight) const;
  72. protected:
  73. //inherited from ccHObject
  74. void drawMeOnly(CC_DRAW_CONTEXT& context) override;
  75. void onDeletionOf(const ccHObject* obj) override;
  76. bool toFile_MeOnly(QFile& out, short dataVersion) const override;
  77. bool fromFile_MeOnly(QFile& in, short dataVersion, int flags, LoadedIDMap& oldToNewIDMap) override;
  78. short minimumFileVersion_MeOnly() const override;
  79. //! Updates aspect ratio
  80. void updateAspectRatio();
  81. protected:
  82. //! Image width (in pixels)
  83. unsigned m_width;
  84. //! Image height (in pixels)
  85. unsigned m_height;
  86. //! Aspect ratio w/h
  87. /** Default is m_width/m_height.
  88. Should be changed if pixels are not square.
  89. **/
  90. float m_aspectRatio;
  91. //! Texture transparency
  92. float m_texAlpha;
  93. //! Image data
  94. QImage m_image;
  95. //! Associated sensor
  96. ccCameraSensor* m_associatedSensor;
  97. };
  98. #endif //CC_IMAGE_HEADER