ctkTransferFunctionTest1.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. // CTK includes
  17. #include "ctkTransferFunction.h"
  18. // STL includes
  19. #include <cstdlib>
  20. #include <iostream>
  21. class ctkDummyTransferFunction: public ctkTransferFunction
  22. {
  23. public:
  24. ctkDummyTransferFunction(QObject* parent = 0):ctkTransferFunction(parent){}
  25. virtual ~ctkDummyTransferFunction(){}
  26. virtual ctkControlPoint* controlPoint(int index)const
  27. {
  28. Q_UNUSED(index);
  29. return 0;
  30. }
  31. virtual QVariant value(qreal pos)const
  32. {
  33. Q_UNUSED(pos);
  34. return 0.;
  35. }
  36. virtual int count()const
  37. {
  38. return 0;
  39. }
  40. virtual bool isDiscrete()const
  41. {
  42. return true;
  43. }
  44. virtual bool isEditable()const
  45. {
  46. return false;
  47. }
  48. virtual void range(qreal& minRange, qreal& maxRange)const
  49. {
  50. minRange = 0.;
  51. maxRange = 0.;
  52. }
  53. virtual QVariant minValue()const
  54. {
  55. return 0.;
  56. }
  57. virtual QVariant maxValue()const
  58. {
  59. return 0.;
  60. }
  61. virtual int insertControlPoint(const ctkControlPoint& cp)
  62. {
  63. Q_UNUSED(cp);
  64. return -1;
  65. }
  66. virtual int insertControlPoint(qreal pos)
  67. {
  68. Q_UNUSED(pos);
  69. return -1;
  70. }
  71. virtual void removeControlPoint( qreal pos )
  72. {
  73. Q_UNUSED(pos);
  74. }
  75. virtual void setControlPointPos(int index, qreal pos)
  76. {
  77. Q_UNUSED(pos);
  78. Q_UNUSED(index);
  79. }
  80. virtual void setControlPointValue(int index, const QVariant& value)
  81. {
  82. Q_UNUSED(index);
  83. Q_UNUSED(value);
  84. }
  85. private:
  86. Q_DISABLE_COPY(ctkDummyTransferFunction);
  87. };
  88. int ctkTransferFunctionTest1(int argc, char * argv [])
  89. {
  90. Q_UNUSED(argc);
  91. Q_UNUSED(argv);
  92. ctkDummyTransferFunction dummy;
  93. if (!dummy.isDiscrete())
  94. {
  95. std::cerr << "Line : " << __LINE__
  96. << " - Problem with ctkHistogram::isDiscrete"
  97. <<std::endl;
  98. return EXIT_FAILURE;
  99. }
  100. if (dummy.isEditable())
  101. {
  102. std::cerr << "Line : " << __LINE__
  103. << " - Problem with ctkHistogram::isEditable"
  104. <<std::endl;
  105. return EXIT_FAILURE;
  106. }
  107. qreal defaultIndex = 0.;
  108. if (dummy.controlPoint(defaultIndex) != 0)
  109. {
  110. std::cerr << "Line : " << __LINE__
  111. << " - Problem with ctkHistogram::controlPoint"
  112. <<std::endl;
  113. return EXIT_FAILURE;
  114. }
  115. if (dummy.count() != 0)
  116. {
  117. std::cerr << "Line : " << __LINE__
  118. << " - Problem with ctkHistogram::count"
  119. <<std::endl;
  120. return EXIT_FAILURE;
  121. }
  122. qreal defaultPos = 0.;
  123. if (dummy.value(defaultPos) != 0)
  124. {
  125. std::cerr << "Line : " << __LINE__
  126. << " - Problem with ctkHistogram::value"
  127. <<std::endl;
  128. return EXIT_FAILURE;
  129. }
  130. if (dummy.value(0) != 0)
  131. {
  132. std::cerr << "Line : " << __LINE__
  133. << " - Problem with ctkHistogram::value"
  134. <<std::endl;
  135. return EXIT_FAILURE;
  136. }
  137. if (dummy.minValue() != 0)
  138. {
  139. std::cerr << "Line : " << __LINE__
  140. << " - Problem with ctkHistogram::minValue"
  141. <<std::endl;
  142. return EXIT_FAILURE;
  143. }
  144. if (dummy.maxValue() != 0)
  145. {
  146. std::cerr << "Line : " << __LINE__
  147. << " - Problem with ctkHistogram::maxValue"
  148. <<std::endl;
  149. return EXIT_FAILURE;
  150. }
  151. if (dummy.insertControlPoint(defaultPos) != -1)
  152. {
  153. std::cerr << "Line : " << __LINE__
  154. << " - Problem with ctkHistogram::insertControlPoint"
  155. <<std::endl;
  156. return EXIT_FAILURE;
  157. }
  158. ctkControlPoint defaultCP;
  159. if (dummy.insertControlPoint(defaultCP) != -1)
  160. {
  161. std::cerr << "Line : " << __LINE__
  162. << " - Problem with ctkHistogram::insertControlPoint"
  163. <<std::endl;
  164. return EXIT_FAILURE;
  165. }
  166. //----------
  167. QVariant defaultValue;
  168. dummy.removeControlPoint(defaultPos);
  169. dummy.setControlPointPos(defaultIndex,defaultPos);
  170. dummy.setControlPointValue(defaultIndex,defaultValue);
  171. dummy.representation();
  172. return EXIT_SUCCESS;
  173. }