ctkTransferFunctionRepresentationTest2.cpp 3.3 KB

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