ctkVTKMatrixWidgetTest1.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <QTimer>
  17. // CTK includes
  18. #include "ctkVTKMatrixWidget.h"
  19. // VTK includes
  20. #include <vtkMatrix4x4.h>
  21. // STD includes
  22. #include <iostream>
  23. //-----------------------------------------------------------------------------
  24. int ctkVTKMatrixWidgetTest1(int argc, char * argv [] )
  25. {
  26. QApplication app(argc, argv);
  27. ctkVTKMatrixWidget matrixWidget(0);
  28. if (matrixWidget.isEnabled())
  29. {
  30. std::cerr << "No vtkMatrix4x4 provided, should be disabled."
  31. << std::endl;
  32. return EXIT_FAILURE;
  33. }
  34. vtkMatrix4x4* matrix = vtkMatrix4x4::New();
  35. matrixWidget.setMatrix(matrix);
  36. matrix->Delete();
  37. if (matrixWidget.matrix() != matrix)
  38. {
  39. std::cerr << "ctkVTKMatrixWidget::setMatrix() failed."
  40. << matrixWidget.matrix() << std::endl;
  41. return EXIT_FAILURE;
  42. }
  43. if (matrixWidget.rowCount() != 4 ||
  44. matrixWidget.columnCount() != 4)
  45. {
  46. std::cerr << "ctkVTKMatrixWidget wrong dimension" << std::endl;
  47. return EXIT_FAILURE;
  48. }
  49. if (matrixWidget.value(3,3) != 1. ||
  50. matrixWidget.value(2,3) != 0.)
  51. {
  52. std::cerr << "Wrong value" << matrixWidget.value(3,3)
  53. << " " << matrixWidget.value(2,3) << std::endl;
  54. return EXIT_FAILURE;
  55. }
  56. matrix->SetElement(1, 3, 50.);
  57. if (!qFuzzyCompare(matrix->GetElement(1,3), 50.) ||
  58. !qFuzzyCompare(matrixWidget.value(1,3), 50.))
  59. {
  60. std::cerr << "vtkMatrix4x4::SetValue() failed:"
  61. << matrix->GetElement(1,3) << " "
  62. << matrixWidget.value(1,3) << std::endl;
  63. return EXIT_FAILURE;
  64. }
  65. matrixWidget.setValue(2,2, -17.);
  66. if (!qFuzzyCompare(matrixWidget.value(2,2), -17.) ||
  67. !qFuzzyCompare(matrix->GetElement(2,2), -17.))
  68. {
  69. std::cerr << "ctkVTKMatrixWidget::setValue() failed:"
  70. << matrix->GetElement(2,2) << " "
  71. << matrixWidget.value(2,2) << std::endl;
  72. return EXIT_FAILURE;
  73. }
  74. matrixWidget.show();
  75. if (argc < 2 || QString(argv[1]) != "-I" )
  76. {
  77. QTimer::singleShot(200, &app, SLOT(quit()));
  78. }
  79. return app.exec();
  80. }