ctkTransferFunction.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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
  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 "CTKCoreExport.h"
  23. //-----------------------------------------------------------------------------
  24. struct CTK_CORE_EXPORT ctkPoint
  25. {
  26. ctkPoint(){}
  27. ctkPoint(qreal x, const QVariant& v)
  28. :X(x),Value(v)
  29. {
  30. }
  31. qreal X;
  32. // QColor or qreal.
  33. QVariant Value;
  34. };
  35. //-----------------------------------------------------------------------------
  36. /// assumes the mapping is linear by default, if not, then subclasses must be
  37. /// used
  38. struct CTK_CORE_EXPORT ctkControlPoint
  39. {
  40. virtual ~ctkControlPoint();
  41. inline const qreal& x()const {return this->P.X;}
  42. inline const QVariant& value()const {return this->P.Value;}
  43. ctkPoint P;
  44. };
  45. //-----------------------------------------------------------------------------
  46. struct CTK_CORE_EXPORT ctkBezierControlPoint : public ctkControlPoint
  47. {
  48. virtual ~ctkBezierControlPoint();
  49. ctkPoint P1;
  50. ctkPoint P2;
  51. };
  52. //-----------------------------------------------------------------------------
  53. struct CTK_CORE_EXPORT ctkNonLinearControlPoint : public ctkControlPoint
  54. {
  55. virtual ~ctkNonLinearControlPoint();
  56. QList<ctkPoint> SubPoints;
  57. };
  58. //-----------------------------------------------------------------------------
  59. class CTK_CORE_EXPORT ctkTransferFunction: public QObject
  60. {
  61. Q_OBJECT
  62. public:
  63. ctkTransferFunction(QObject* parent = 0);
  64. virtual ~ctkTransferFunction();
  65. virtual ctkControlPoint* controlPoint(int index)const = 0;
  66. inline QVariant value(int index)const;
  67. virtual QVariant value(qreal pos)const = 0;
  68. virtual int count()const = 0;
  69. inline void range(qreal rangeValues[2])const;
  70. virtual void range(qreal& minRange, qreal& maxRange)const=0;
  71. virtual QVariant minValue()const = 0;
  72. virtual QVariant maxValue()const = 0;
  73. ///
  74. virtual int insertControlPoint(const ctkControlPoint& cp) = 0;
  75. ///
  76. /// be careful with it, as changing the value might require
  77. /// more changes to ctkControlPoint.
  78. virtual void setControlPointPos(int index, qreal pos)=0;
  79. ///
  80. /// be careful with it, as changing the value might require
  81. /// more changes to ctkControlPoint.
  82. virtual void setControlPointValue(int index, const QVariant& value)=0;
  83. virtual ctkBezierControlPoint* toto();
  84. signals:
  85. void changed();
  86. };
  87. //-----------------------------------------------------------------------------
  88. QVariant ctkTransferFunction::value(int index)const
  89. {
  90. QSharedPointer<ctkControlPoint> cp(this->controlPoint(index));
  91. return cp->P.Value;
  92. }
  93. //-----------------------------------------------------------------------------
  94. void ctkTransferFunction::range(qreal rangeValues[2])const
  95. {
  96. this->range(rangeValues[0], rangeValues[1]);
  97. }
  98. #endif