ctkHistogramTest1.cpp 4.8 KB

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