ctkHistogramTest1.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 void range(qreal& minRange, qreal& maxRange)const
  44. {
  45. Q_UNUSED(minRange);
  46. Q_UNUSED(maxRange);
  47. minRange = 0.;
  48. maxRange = 0.;
  49. }
  50. virtual QVariant minValue()const
  51. {
  52. return 0;
  53. }
  54. virtual QVariant maxValue()const
  55. {
  56. return 0;
  57. }
  58. virtual void removeControlPoint( qreal pos )
  59. {
  60. Q_UNUSED(pos);
  61. }
  62. virtual void build()
  63. {
  64. }
  65. protected:
  66. };
  67. int ctkHistogramTest1(int argc, char * argv [] )
  68. {
  69. Q_UNUSED(argc);
  70. Q_UNUSED(argv);
  71. ctkDummyHistogram dummyHistogram;
  72. if (!dummyHistogram.isDiscrete())
  73. {
  74. std::cerr << "Line : " << __LINE__
  75. << " - Problem with ctkHistogram::isDiscrete"
  76. <<std::endl;
  77. return EXIT_FAILURE;
  78. }
  79. if (dummyHistogram.isEditable())
  80. {
  81. std::cerr << "Line : " << __LINE__
  82. << " - Problem with ctkHistogram::isEditable"
  83. <<std::endl;
  84. return EXIT_FAILURE;
  85. }
  86. qreal defaultIndex = 0.;
  87. if (dummyHistogram.controlPoint(defaultIndex) != 0)
  88. {
  89. std::cerr << "Line : " << __LINE__
  90. << " - Problem with ctkHistogram::controlPoint"
  91. <<std::endl;
  92. return EXIT_FAILURE;
  93. }
  94. if (dummyHistogram.count() != 0)
  95. {
  96. std::cerr << "Line : " << __LINE__
  97. << " - Problem with ctkHistogram::count"
  98. <<std::endl;
  99. return EXIT_FAILURE;
  100. }
  101. qreal defaultPos = 0.;
  102. if (dummyHistogram.value(defaultPos) != 0)
  103. {
  104. std::cerr << "Line : " << __LINE__
  105. << " - Problem with ctkHistogram::value"
  106. <<std::endl;
  107. return EXIT_FAILURE;
  108. }
  109. if (dummyHistogram.minValue() != 0)
  110. {
  111. std::cerr << "Line : " << __LINE__
  112. << " - Problem with ctkHistogram::minValue"
  113. <<std::endl;
  114. return EXIT_FAILURE;
  115. }
  116. if (dummyHistogram.maxValue() != 0)
  117. {
  118. std::cerr << "Line : " << __LINE__
  119. << " - Problem with ctkHistogram::maxValue"
  120. <<std::endl;
  121. return EXIT_FAILURE;
  122. }
  123. if (dummyHistogram.insertControlPoint(defaultPos) != -1)
  124. {
  125. std::cerr << "Line : " << __LINE__
  126. << " - Problem with ctkHistogram::insertControlPoint"
  127. <<std::endl;
  128. return EXIT_FAILURE;
  129. }
  130. ctkControlPoint defaultCP;
  131. if (dummyHistogram.insertControlPoint(defaultCP) != -1)
  132. {
  133. std::cerr << "Line : " << __LINE__
  134. << " - Problem with ctkHistogram::insertControlPoint"
  135. <<std::endl;
  136. return EXIT_FAILURE;
  137. }
  138. //----------
  139. QVariant defaultValue;
  140. dummyHistogram.removeControlPoint(defaultPos);
  141. dummyHistogram.setControlPointPos(defaultIndex,defaultPos);
  142. dummyHistogram.setControlPointValue(defaultIndex,defaultValue);
  143. dummyHistogram.build();
  144. return EXIT_SUCCESS;
  145. }