ctkVTKSurfaceMaterialPropertyWidgetTest1.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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.apache.org/licenses/LICENSE-2.0.txt
  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 <QApplication>
  16. #include <QDebug>
  17. #include <QTimer>
  18. // CTK includes
  19. #include "ctkVTKSurfaceMaterialPropertyWidget.h"
  20. // VTK includes
  21. #include <vtkProperty.h>
  22. // STD includes
  23. #include <iostream>
  24. //-----------------------------------------------------------------------------
  25. int ctkVTKSurfaceMaterialPropertyWidgetTest1(int argc, char * argv [] )
  26. {
  27. QApplication app(argc, argv);
  28. ctkVTKSurfaceMaterialPropertyWidget propertyWidget(0);
  29. if (propertyWidget.isEnabled())
  30. {
  31. std::cerr << "No vtkProperty provided, should be disabled."
  32. << std::endl;
  33. return EXIT_FAILURE;
  34. }
  35. vtkProperty* property = vtkProperty::New();
  36. double color[3];
  37. property->GetColor(color);
  38. double opacity = property->GetOpacity();
  39. double ambient = property->GetAmbient();
  40. double diffuse = property->GetDiffuse();
  41. double specular = property->GetSpecular();
  42. double specularPower = property->GetSpecularPower();
  43. bool backfaceCulling = property->GetBackfaceCulling();
  44. propertyWidget.setProperty(property);
  45. property->Delete();
  46. if (propertyWidget.property() != property)
  47. {
  48. std::cerr << "ctkVTKSurfaceMaterialPropertyWidget::setProperty() failed."
  49. << propertyWidget.property() << std::endl;
  50. return EXIT_FAILURE;
  51. }
  52. if (propertyWidget.color() != QColor::fromRgbF(color[0],color[1],color[2]))
  53. {
  54. std::cerr << "Wrong color: " << propertyWidget.color().rgb() << std::endl;
  55. return EXIT_FAILURE;
  56. }
  57. if (propertyWidget.opacity() != opacity)
  58. {
  59. std::cerr << "Wrong opacity: " << propertyWidget.opacity() << std::endl;
  60. return EXIT_FAILURE;
  61. }
  62. if (propertyWidget.ambient() != ambient)
  63. {
  64. std::cerr << "Wrong ambient: " << propertyWidget.ambient() << std::endl;
  65. return EXIT_FAILURE;
  66. }
  67. if (propertyWidget.diffuse() != diffuse)
  68. {
  69. std::cerr << "Wrong diffuse: " << propertyWidget.diffuse() << std::endl;
  70. return EXIT_FAILURE;
  71. }
  72. if (propertyWidget.specular() != specular)
  73. {
  74. std::cerr << "Wrong specular: " << propertyWidget.specular() << std::endl;
  75. return EXIT_FAILURE;
  76. }
  77. if (propertyWidget.specularPower() != specularPower)
  78. {
  79. std::cerr << "Wrong specularPower: " << propertyWidget.specularPower() << std::endl;
  80. return EXIT_FAILURE;
  81. }
  82. if (propertyWidget.backfaceCulling() != backfaceCulling)
  83. {
  84. std::cerr << "Wrong backfaceCulling: " << propertyWidget.backfaceCulling() << std::endl;
  85. return EXIT_FAILURE;
  86. }
  87. property->SetColor(1., 1., 1.);
  88. if (propertyWidget.color() != QColor::fromRgbF(1., 1., 1.))
  89. {
  90. std::cerr << "vtkProperty::SetColor() failed: " << propertyWidget.color().rgb() << std::endl;
  91. return EXIT_FAILURE;
  92. }
  93. propertyWidget.setColor(Qt::red);
  94. property->GetColor(color);
  95. if (color[0] != 1. || color[1] != 0. || color[2] !=0)
  96. {
  97. std::cerr << "ctkVTKSurfaceMaterialPropertyWidget::setColor() failed: "
  98. << color[0] << " " << color[1] << " " << color[2] << std::endl;
  99. return EXIT_FAILURE;
  100. }
  101. property->SetOpacity(0.111);
  102. // Only 2 decimals are supported by the widget
  103. if (propertyWidget.opacity() != 0.11)
  104. {
  105. std::cerr << "vtkProperty::SetOpacity() failed: " << propertyWidget.opacity() << std::endl;
  106. return EXIT_FAILURE;
  107. }
  108. propertyWidget.setOpacity(0.999);
  109. if (property->GetOpacity() != 1.00)
  110. {
  111. std::cerr << "ctkVTKSurfaceMaterialPropertyWidget::setOpacity() failed: "
  112. << property->GetOpacity() << std::endl;
  113. return EXIT_FAILURE;
  114. }
  115. property->SetAmbient(0.5);
  116. if (propertyWidget.ambient() != 0.5)
  117. {
  118. std::cerr << "vtkProperty::SetAmbient() failed: " << propertyWidget.ambient() << std::endl;
  119. return EXIT_FAILURE;
  120. }
  121. propertyWidget.setAmbient(0.8);
  122. if (property->GetAmbient() != 0.8)
  123. {
  124. std::cerr << "ctkVTKSurfaceMaterialPropertyWidget::setAmbient() failed: "
  125. << property->GetAmbient() << std::endl;
  126. return EXIT_FAILURE;
  127. }
  128. property->SetDiffuse(1.2);
  129. if (propertyWidget.diffuse() != 1.)
  130. {
  131. std::cerr << "vtkProperty::SetDiffuse() failed: " << propertyWidget.diffuse() << std::endl;
  132. return EXIT_FAILURE;
  133. }
  134. propertyWidget.setDiffuse(0.3);
  135. if (property->GetDiffuse() != 0.3)
  136. {
  137. std::cerr << "ctkVTKSurfaceMaterialPropertyWidget::setDiffuse() failed: "
  138. << property->GetDiffuse() << std::endl;
  139. return EXIT_FAILURE;
  140. }
  141. property->SetSpecular(0.99);
  142. if (propertyWidget.specular() != 0.99)
  143. {
  144. std::cerr << "vtkProperty::SetSpecular() failed: " << propertyWidget.specular() << std::endl;
  145. return EXIT_FAILURE;
  146. }
  147. propertyWidget.setSpecular(0.01);
  148. if (property->GetSpecular() != 0.01)
  149. {
  150. std::cerr << "ctkVTKSurfaceMaterialPropertyWidget::setSpecular() failed: "
  151. << property->GetSpecular() << std::endl;
  152. return EXIT_FAILURE;
  153. }
  154. property->SetSpecularPower(45);
  155. if (propertyWidget.specularPower() != 45)
  156. {
  157. std::cerr << "vtkProperty::SetSpecularPower() failed: " << propertyWidget.specularPower() << std::endl;
  158. return EXIT_FAILURE;
  159. }
  160. propertyWidget.setSpecularPower(60);
  161. if (property->GetSpecularPower() != 50)
  162. {
  163. std::cerr << "ctkVTKSurfaceMaterialPropertyWidget::setSpecularPower() failed: "
  164. << property->GetSpecularPower() << std::endl;
  165. return EXIT_FAILURE;
  166. }
  167. property->SetBackfaceCulling(false);
  168. if (propertyWidget.backfaceCulling() != false)
  169. {
  170. std::cerr << "vtkProperty::SetBackfaceCulling() failed: " << propertyWidget.backfaceCulling() << std::endl;
  171. return EXIT_FAILURE;
  172. }
  173. propertyWidget.setBackfaceCulling(true);
  174. if (property->GetBackfaceCulling() != 1)
  175. {
  176. std::cerr << "ctkVTKSurfaceMaterialPropertyWidget::setBackfaceCulling() failed: "
  177. << property->GetBackfaceCulling() << std::endl;
  178. return EXIT_FAILURE;
  179. }
  180. propertyWidget.show();
  181. if (argc < 2 || QString(argv[1]) != "-I" )
  182. {
  183. QTimer::singleShot(200, &app, SLOT(quit()));
  184. }
  185. return app.exec();
  186. }