qwt_transform.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
  2. * Qwt Widget Library
  3. * Copyright (C) 1997 Josef Wilgen
  4. * Copyright (C) 2002 Uwe Rathmann
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the Qwt License, Version 1.0
  8. *****************************************************************************/
  9. #ifndef QWT_TRANSFORM_H
  10. #define QWT_TRANSFORM_H
  11. #include "qwt_global.h"
  12. /*!
  13. \brief A transformation between coordinate systems
  14. QwtTransform manipulates values, when being mapped between
  15. the scale and the paint device coordinate system.
  16. A transformation consists of 2 methods:
  17. - transform
  18. - invTransform
  19. where one is is the inverse function of the other.
  20. When p1, p2 are the boundaries of the paint device coordinates
  21. and s1, s2 the boundaries of the scale, QwtScaleMap uses the
  22. following calculations:
  23. - p = p1 + ( p2 - p1 ) * ( T( s ) - T( s1 ) / ( T( s2 ) - T( s1 ) );
  24. - s = invT ( T( s1 ) + ( T( s2 ) - T( s1 ) ) * ( p - p1 ) / ( p2 - p1 ) );
  25. */
  26. class QWT_EXPORT QwtTransform
  27. {
  28. public:
  29. QwtTransform();
  30. virtual ~QwtTransform();
  31. /*!
  32. Modify value to be a valid value for the transformation.
  33. The default implementation does nothing.
  34. */
  35. virtual double bounded( double value ) const;
  36. /*!
  37. Transformation function
  38. \param value Value
  39. \return Modified value
  40. \sa invTransform()
  41. */
  42. virtual double transform( double value ) const = 0;
  43. /*!
  44. Inverse transformation function
  45. \param value Value
  46. \return Modified value
  47. \sa transform()
  48. */
  49. virtual double invTransform( double value ) const = 0;
  50. //! Virtualized copy operation
  51. virtual QwtTransform *copy() const = 0;
  52. };
  53. /*!
  54. \brief Null transformation
  55. QwtNullTransform returns the values unmodified.
  56. */
  57. class QWT_EXPORT QwtNullTransform: public QwtTransform
  58. {
  59. public:
  60. QwtNullTransform();
  61. virtual ~QwtNullTransform();
  62. virtual double transform( double value ) const;
  63. virtual double invTransform( double value ) const;
  64. virtual QwtTransform *copy() const;
  65. };
  66. /*!
  67. \brief Logarithmic transformation
  68. QwtLogTransform modifies the values using log() and exp().
  69. \note In the calculations of QwtScaleMap the base of the log function
  70. has no effect on the mapping. So QwtLogTransform can be used
  71. for log2(), log10() or any other logarithmic scale.
  72. */
  73. class QWT_EXPORT QwtLogTransform: public QwtTransform
  74. {
  75. public:
  76. QwtLogTransform();
  77. virtual ~QwtLogTransform();
  78. virtual double transform( double value ) const;
  79. virtual double invTransform( double value ) const;
  80. virtual double bounded( double value ) const;
  81. virtual QwtTransform *copy() const;
  82. #if QT_VERSION >= 0x050400
  83. static const double LogMin;
  84. static const double LogMax;
  85. #else
  86. QT_STATIC_CONST double LogMin;
  87. QT_STATIC_CONST double LogMax;
  88. #endif
  89. };
  90. /*!
  91. \brief A transformation using pow()
  92. QwtPowerTransform preserves the sign of a value.
  93. F.e. a transformation with a factor of 2
  94. transforms a value of -3 to -9 and v.v. Thus QwtPowerTransform
  95. can be used for scales including negative values.
  96. */
  97. class QWT_EXPORT QwtPowerTransform: public QwtTransform
  98. {
  99. public:
  100. QwtPowerTransform( double exponent );
  101. virtual ~QwtPowerTransform();
  102. virtual double transform( double value ) const;
  103. virtual double invTransform( double value ) const;
  104. virtual QwtTransform *copy() const;
  105. private:
  106. const double d_exponent;
  107. };
  108. #endif