ctkTransferFunction.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 __ctkTransferFunction_h
  15. #define __ctkTransferFunction_h
  16. /// Qt includes
  17. #include <QObject>
  18. #include <QtGlobal>
  19. #include <QSharedPointer>
  20. #include <QVariant>
  21. /// CTK includes
  22. #include "ctkPimpl.h"
  23. #include "ctkWidgetsExport.h"
  24. class ctkTransferFunctionPrivate;
  25. class ctkTransferFunctionRepresentation;
  26. //-----------------------------------------------------------------------------
  27. /// \ingroup Widgets
  28. struct CTK_WIDGETS_EXPORT ctkPoint
  29. {
  30. ctkPoint()
  31. :X(0),Value(0)
  32. {
  33. }
  34. ctkPoint(qreal x, const QVariant& v)
  35. :X(x),Value(v)
  36. {
  37. }
  38. qreal X;
  39. // QColor or qreal.
  40. QVariant Value;
  41. };
  42. //-----------------------------------------------------------------------------
  43. /// \ingroup Widgets
  44. /// assumes the mapping is linear by default, if not, then subclasses must be
  45. /// used
  46. struct CTK_WIDGETS_EXPORT ctkControlPoint
  47. {
  48. virtual ~ctkControlPoint();
  49. inline const qreal& x()const {return this->P.X;}
  50. inline const QVariant& value()const {return this->P.Value;}
  51. ctkPoint P;
  52. };
  53. //-----------------------------------------------------------------------------
  54. /// \ingroup Widgets
  55. struct CTK_WIDGETS_EXPORT ctkBezierControlPoint : public ctkControlPoint
  56. {
  57. virtual ~ctkBezierControlPoint();
  58. ctkPoint P1;
  59. ctkPoint P2;
  60. };
  61. //-----------------------------------------------------------------------------
  62. /// \ingroup Widgets
  63. struct CTK_WIDGETS_EXPORT ctkNonLinearControlPoint : public ctkControlPoint
  64. {
  65. virtual ~ctkNonLinearControlPoint();
  66. QList<ctkPoint> SubPoints;
  67. };
  68. //-----------------------------------------------------------------------------
  69. /// \ingroup Widgets
  70. class CTK_WIDGETS_EXPORT ctkTransferFunction: public QObject
  71. {
  72. Q_OBJECT
  73. public:
  74. ctkTransferFunction(QObject* parent = 0);
  75. virtual ~ctkTransferFunction();
  76. virtual ctkControlPoint* controlPoint(int index)const = 0;
  77. inline QVariant value(int index)const;
  78. virtual QVariant value(qreal pos)const = 0;
  79. virtual int count()const = 0;
  80. virtual bool isDiscrete()const = 0;
  81. virtual bool isEditable()const = 0;
  82. inline void range(qreal rangeValues[2])const;
  83. virtual void range(qreal& minRange, qreal& maxRange)const=0;
  84. virtual QVariant minValue()const = 0;
  85. virtual QVariant maxValue()const = 0;
  86. inline void valueRange(QVariant range[2])const;
  87. ///
  88. virtual int insertControlPoint(const ctkControlPoint& cp) = 0;
  89. virtual int insertControlPoint(qreal pos) = 0;
  90. virtual void removeControlPoint( qreal pos ) = 0;
  91. ///
  92. /// be careful with it, as changing the value might require
  93. /// more changes to ctkControlPoint.
  94. virtual void setControlPointPos(int index, qreal pos)=0;
  95. ///
  96. /// be careful with it, as changing the value might require
  97. /// more changes to ctkControlPoint.
  98. virtual void setControlPointValue(int index, const QVariant& value)=0;
  99. ctkTransferFunctionRepresentation* representation()const;
  100. Q_SIGNALS:
  101. void changed();
  102. protected:
  103. QScopedPointer<ctkTransferFunctionPrivate> d_ptr;
  104. private:
  105. Q_DECLARE_PRIVATE(ctkTransferFunction);
  106. Q_DISABLE_COPY(ctkTransferFunction);
  107. };
  108. //-----------------------------------------------------------------------------
  109. QVariant ctkTransferFunction::value(int index)const
  110. {
  111. QSharedPointer<ctkControlPoint> cp(this->controlPoint(index));
  112. return cp->P.Value;
  113. }
  114. //-----------------------------------------------------------------------------
  115. void ctkTransferFunction::range(qreal rangeValues[2])const
  116. {
  117. this->range(rangeValues[0], rangeValues[1]);
  118. }
  119. //-----------------------------------------------------------------------------
  120. void ctkTransferFunction::valueRange(QVariant rangeValues[2])const
  121. {
  122. rangeValues[0] = this->minValue();
  123. rangeValues[1] = this->maxValue();
  124. }
  125. #endif