ctkTransferFunctionRepresentationTest2.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.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. // Qt includes
  15. #include <QCoreApplication>
  16. #include <QColor>
  17. // CTK includes
  18. #include "ctkTransferFunction.h"
  19. #include "ctkTransferFunctionRepresentation.h"
  20. // STL includes
  21. #include <cstdlib>
  22. #include <iostream>
  23. class ctkForcedTransferFunction: public ctkTransferFunction
  24. {
  25. public:
  26. ctkForcedTransferFunction(QObject* parent = 0):ctkTransferFunction(parent), _discrete(true) {}
  27. virtual ~ctkForcedTransferFunction(){}
  28. // attributes test
  29. bool _discrete;
  30. virtual ctkControlPoint* controlPoint(int index)const
  31. {
  32. QColor rgb = QColor::fromRgbF(55, 56, 57);
  33. ctkControlPoint* cp = new ctkControlPoint();
  34. cp->P.X = index;
  35. cp->P.Value = rgb;
  36. return cp;
  37. }
  38. virtual QVariant value(qreal pos)const
  39. {
  40. QColor rgb = QColor::fromRgbF(55, static_cast<int>(pos), 57);
  41. return rgb;
  42. }
  43. virtual int count()const
  44. {
  45. return 2;
  46. }
  47. virtual bool isDiscrete()const
  48. {
  49. return _discrete;
  50. }
  51. virtual bool isEditable()const
  52. {
  53. return false;
  54. }
  55. virtual void range(qreal& minRange, qreal& maxRange)const
  56. {
  57. minRange = 0.;
  58. maxRange = 1.;
  59. }
  60. virtual QVariant minValue()const
  61. {
  62. return 0.;
  63. }
  64. virtual QVariant maxValue()const
  65. {
  66. return 0.;
  67. }
  68. virtual int insertControlPoint(const ctkControlPoint& cp)
  69. {
  70. Q_UNUSED(cp);
  71. return -1;
  72. }
  73. virtual int insertControlPoint(qreal pos)
  74. {
  75. Q_UNUSED(pos);
  76. return -1;
  77. }
  78. virtual void removeControlPoint( qreal pos )
  79. {
  80. Q_UNUSED(pos);
  81. }
  82. virtual void setControlPointPos(int index, qreal pos)
  83. {
  84. Q_UNUSED(pos);
  85. Q_UNUSED(index);
  86. }
  87. virtual void setControlPointValue(int index, const QVariant& value)
  88. {
  89. Q_UNUSED(index);
  90. Q_UNUSED(value);
  91. }
  92. };
  93. int ctkTransferFunctionRepresentationTest2( int argc, char * argv [])
  94. {
  95. Q_UNUSED(argc);
  96. Q_UNUSED(argv);
  97. ctkForcedTransferFunction* dummy = new ctkForcedTransferFunction();
  98. ctkTransferFunctionRepresentation representation;
  99. representation.setTransferFunction(dummy);
  100. representation.computeCurve();
  101. representation.computeGradient();
  102. dummy->_discrete = false;
  103. representation.setTransferFunction(dummy);
  104. representation.computeCurve();
  105. representation.computeGradient();
  106. delete dummy;
  107. return EXIT_SUCCESS;
  108. }