ctkVTKSurfaceMaterialPropertyWidgetTest1.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 <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 ambient = property->GetAmbient();
  37. double diffuse = property->GetDiffuse();
  38. double specular = property->GetSpecular();
  39. double specularPower = property->GetSpecularPower();
  40. propertyWidget.setProperty(property);
  41. property->Delete();
  42. if (propertyWidget.property() != property)
  43. {
  44. std::cerr << "ctkVTKSurfaceMaterialPropertyWidget::setProperty() failed."
  45. << propertyWidget.property() << std::endl;
  46. return EXIT_FAILURE;
  47. }
  48. if (propertyWidget.ambient() != ambient)
  49. {
  50. std::cerr << "Wrong ambient: " << propertyWidget.ambient() << std::endl;
  51. return EXIT_FAILURE;
  52. }
  53. if (propertyWidget.diffuse() != diffuse)
  54. {
  55. std::cerr << "Wrong diffuse: " << propertyWidget.diffuse() << std::endl;
  56. return EXIT_FAILURE;
  57. }
  58. if (propertyWidget.specular() != specular)
  59. {
  60. std::cerr << "Wrong specular: " << propertyWidget.specular() << std::endl;
  61. return EXIT_FAILURE;
  62. }
  63. if (propertyWidget.specularPower() != specularPower)
  64. {
  65. std::cerr << "Wrong specularPower: " << propertyWidget.specularPower() << std::endl;
  66. return EXIT_FAILURE;
  67. }
  68. property->SetAmbient(0.5);
  69. if (propertyWidget.ambient() != 0.5)
  70. {
  71. std::cerr << "vtkProperty::SetAmbient() failed: " << propertyWidget.ambient() << std::endl;
  72. return EXIT_FAILURE;
  73. }
  74. // QColor handles floating points on 16bit integers
  75. propertyWidget.setAmbient(0.8);
  76. if (property->GetAmbient() != 0.8)
  77. {
  78. std::cerr << "ctkVTKSurfaceMaterialPropertyWidget::setAmbient() failed: "
  79. << property->GetAmbient() << std::endl;
  80. return EXIT_FAILURE;
  81. }
  82. property->SetDiffuse(1.2);
  83. if (propertyWidget.diffuse() != 1.)
  84. {
  85. std::cerr << "vtkProperty::SetDiffuse() failed: " << propertyWidget.diffuse() << std::endl;
  86. return EXIT_FAILURE;
  87. }
  88. // QColor handles floating points on 16bit integers
  89. propertyWidget.setDiffuse(0.3);
  90. if (property->GetDiffuse() != 0.3)
  91. {
  92. std::cerr << "ctkVTKSurfaceMaterialPropertyWidget::setDiffuse() failed: "
  93. << property->GetDiffuse() << std::endl;
  94. return EXIT_FAILURE;
  95. }
  96. property->SetSpecular(0.99);
  97. if (propertyWidget.specular() != 0.99)
  98. {
  99. std::cerr << "vtkProperty::SetSpecular() failed: " << propertyWidget.specular() << std::endl;
  100. return EXIT_FAILURE;
  101. }
  102. // QColor handles floating points on 16bit integers
  103. propertyWidget.setSpecular(0.01);
  104. if (property->GetSpecular() != 0.01)
  105. {
  106. std::cerr << "ctkVTKSurfaceMaterialPropertyWidget::setSpecular() failed: "
  107. << property->GetSpecular() << std::endl;
  108. return EXIT_FAILURE;
  109. }
  110. property->SetSpecularPower(45);
  111. if (propertyWidget.specularPower() != 45)
  112. {
  113. std::cerr << "vtkProperty::SetSpecularPower() failed: " << propertyWidget.specularPower() << std::endl;
  114. return EXIT_FAILURE;
  115. }
  116. // QColor handles floating points on 16bit integers
  117. propertyWidget.setSpecularPower(60);
  118. if (property->GetSpecularPower() != 50)
  119. {
  120. std::cerr << "ctkVTKSurfaceMaterialPropertyWidget::setSpecularPower() failed: "
  121. << property->GetSpecularPower() << std::endl;
  122. return EXIT_FAILURE;
  123. }
  124. propertyWidget.show();
  125. if (argc < 2 || QString(argv[1]) != "-I" )
  126. {
  127. QTimer::singleShot(200, &app, SLOT(quit()));
  128. }
  129. return app.exec();
  130. }