ctkTransferFunction.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*=========================================================================
  2. Library: ctk
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. #ifndef __ctkTransferFunction_h
  11. #define __ctkTransferFunction_h
  12. /// Qt includes
  13. #include <QObject>
  14. #include <QtGlobal>
  15. #include <QSharedPointer>
  16. #include <QVariant>
  17. /// CTK includes
  18. #include "CTKCoreExport.h"
  19. /// assumes the mapping is linear by default, if not, then subclasses must be
  20. /// used
  21. //-----------------------------------------------------------------------------
  22. struct ctkControlPoint
  23. {
  24. virtual ~ctkControlPoint(){}
  25. // QColor or qreal.
  26. QVariant Value;
  27. qreal Pos;
  28. };
  29. //-----------------------------------------------------------------------------
  30. struct ctkBezierControlPoint : public ctkControlPoint
  31. {
  32. qreal P1;
  33. QVariant ValueP1;
  34. qreal P2;
  35. QVariant ValueP2;
  36. };
  37. //-----------------------------------------------------------------------------
  38. class CTK_CORE_EXPORT ctkTransferFunction: public QObject
  39. {
  40. Q_OBJECT
  41. public:
  42. ctkTransferFunction(QObject* parent = 0);
  43. virtual ~ctkTransferFunction();
  44. virtual ctkControlPoint* controlPoint(int index)const =0;
  45. inline QVariant value(int index)const;
  46. virtual QVariant value(qreal pos)const =0;
  47. virtual int count()const = 0;
  48. inline void range(qreal rangeValues[2])const;
  49. virtual void range(qreal& minRange, qreal& maxRange)const=0;
  50. virtual QVariant minValue()const = 0;
  51. virtual QVariant maxValue()const = 0;
  52. ///
  53. virtual int insertControlPoint(const ctkControlPoint& cp) = 0;
  54. ///
  55. /// be careful with it, as changing the value might require
  56. /// more changes to ctkControlPoint.
  57. virtual void setControlPointPos(int index, qreal pos)=0;
  58. ///
  59. /// be careful with it, as changing the value might require
  60. /// more changes to ctkControlPoint.
  61. virtual void setControlPointValue(int index, const QVariant& value)=0;
  62. signals:
  63. void changed();
  64. };
  65. //-----------------------------------------------------------------------------
  66. QVariant ctkTransferFunction::value(int index)const
  67. {
  68. QSharedPointer<ctkControlPoint> cp(this->controlPoint(index));
  69. return cp->Value;
  70. }
  71. //-----------------------------------------------------------------------------
  72. void ctkTransferFunction::range(qreal rangeValues[2])const
  73. {
  74. this->range(rangeValues[0], rangeValues[1]);
  75. }
  76. #endif