ctkTransferFunction.h 4.1 KB

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