ctkTransferFunctionRepresentation.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkTransferFunctionRepresentation_h
  15. #define __ctkTransferFunctionRepresentation_h
  16. /// Qt includes
  17. #include <QColor>
  18. #include <QGradient>
  19. #include <QObject>
  20. #include <QPainterPath>
  21. /// CTK includes
  22. #include "ctkPimpl.h"
  23. #include "ctkTransferFunction.h"
  24. #include "ctkWidgetsExport.h"
  25. class ctkTransferFunction;
  26. class ctkTransferFunctionRepresentationPrivate;
  27. //-----------------------------------------------------------------------------
  28. /// \ingroup Widgets
  29. class CTK_WIDGETS_EXPORT ctkTransferFunctionRepresentation: public QObject
  30. {
  31. Q_OBJECT
  32. Q_PROPERTY(QColor verticalGradientColor READ verticalGradientColor WRITE setVerticalGradientColor)
  33. public:
  34. /// Construct a representation with no transfer function.
  35. ctkTransferFunctionRepresentation(QObject* parent = 0);
  36. /// Construct a representation with transfer function.
  37. ctkTransferFunctionRepresentation(ctkTransferFunction* transferFunction, QObject* parent = 0);
  38. virtual ~ctkTransferFunctionRepresentation();
  39. void setTransferFunction(ctkTransferFunction* transferFunction);
  40. ctkTransferFunction* transferFunction()const;
  41. inline qreal posX(const ctkControlPoint* cp)const;
  42. inline qreal posY(const ctkControlPoint* cp)const;
  43. inline QColor color(const ctkControlPoint* cp) const;
  44. inline qreal posX(const ctkPoint& point)const;
  45. inline qreal posY(const ctkPoint& point)const;
  46. inline QColor color(const ctkPoint& point) const;
  47. qreal posX(const qreal& tfX)const;
  48. qreal posY(const QVariant& tfV)const;
  49. QColor color(const QVariant& tfV) const;
  50. QPointF mapPointToScene(const ctkControlPoint* cp)const;
  51. QPointF mapPointToScene(const ctkPoint& point)const;
  52. qreal mapXToScene(qreal posX)const;
  53. qreal mapYToScene(qreal posY)const;
  54. qreal mapXFromScene(qreal ScenePosX)const;
  55. qreal mapYFromScene(qreal ScenePosY)const;
  56. inline QPointF mapPointFromScene(const QPointF& point)const;
  57. QList<ctkPoint> bezierParams(ctkControlPoint* start, ctkControlPoint* end) const;
  58. QList<ctkPoint> nonLinearPoints(ctkControlPoint* start, ctkControlPoint* end) const;
  59. const QPainterPath& curve()const;
  60. const QList<QPointF>& points()const;
  61. const QGradient& gradient()const;
  62. void computeCurve();
  63. void computeGradient();
  64. QColor verticalGradientColor()const;
  65. void setVerticalGradientColor(QColor verticalGradientColor);
  66. protected Q_SLOTS:
  67. virtual void onTransferFunctionChanged();
  68. protected:
  69. qreal computeRangeXDiff(const QRectF& rect, qreal rangeX[2]);
  70. qreal computeRangeXOffset(qreal rangeX[2]);
  71. qreal computeRangeYDiff(const QRectF& rect, const QVariant rangeY[2]);
  72. qreal computeRangeYOffset(const QVariant rangeY[2]);
  73. protected:
  74. QScopedPointer<ctkTransferFunctionRepresentationPrivate> d_ptr;
  75. private:
  76. Q_DECLARE_PRIVATE(ctkTransferFunctionRepresentation);
  77. Q_DISABLE_COPY(ctkTransferFunctionRepresentation);
  78. };
  79. qreal ctkTransferFunctionRepresentation::posX(const ctkControlPoint* cp)const
  80. {
  81. return this->posX(cp->x());
  82. }
  83. qreal ctkTransferFunctionRepresentation::posY(const ctkControlPoint* cp)const
  84. {
  85. return this->posY(cp->value());
  86. }
  87. QColor ctkTransferFunctionRepresentation::color(const ctkControlPoint* cp) const
  88. {
  89. return this->color(cp->value());
  90. }
  91. qreal ctkTransferFunctionRepresentation::posX(const ctkPoint& point)const
  92. {
  93. return this->posX(point.X);
  94. }
  95. qreal ctkTransferFunctionRepresentation::posY(const ctkPoint& point)const
  96. {
  97. return this->posY(point.Value);
  98. }
  99. QColor ctkTransferFunctionRepresentation::color(const ctkPoint& point) const
  100. {
  101. return this->color(point.Value);
  102. }
  103. QPointF ctkTransferFunctionRepresentation::mapPointFromScene(const QPointF& point)const
  104. {
  105. return QPointF(this->mapXFromScene(point.x()),
  106. this->mapYFromScene(point.y()));
  107. }
  108. #endif