ctkVTKAbstractMatrixWidget.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. // Qt includes
  11. #include <QDebug>
  12. #include <QVector>
  13. // CTK includes
  14. #include "ctkVTKAbstractMatrixWidget_p.h"
  15. #include "ctkVTKAbstractMatrixWidget.h"
  16. // VTK includes
  17. #include <vtkMatrix4x4.h>
  18. // --------------------------------------------------------------------------
  19. ctkVTKAbstractMatrixWidgetPrivate::ctkVTKAbstractMatrixWidgetPrivate()
  20. :QObject(0) // will be reparented in init()
  21. {
  22. }
  23. void ctkVTKAbstractMatrixWidgetPrivate::init()
  24. {
  25. CTK_P(ctkVTKAbstractMatrixWidget);
  26. this->setParent(p);
  27. this->updateMatrix();
  28. }
  29. // --------------------------------------------------------------------------
  30. void ctkVTKAbstractMatrixWidgetPrivate::setMatrix(vtkMatrix4x4* matrixVariable)
  31. {
  32. qvtkReconnect(this->Matrix.GetPointer(), matrixVariable,
  33. vtkCommand::ModifiedEvent, this, SLOT(updateMatrix()));
  34. this->Matrix = matrixVariable;
  35. this->updateMatrix();
  36. }
  37. // --------------------------------------------------------------------------
  38. vtkMatrix4x4* ctkVTKAbstractMatrixWidgetPrivate::matrix() const
  39. {
  40. return this->Matrix;
  41. }
  42. // --------------------------------------------------------------------------
  43. void ctkVTKAbstractMatrixWidgetPrivate::updateMatrix()
  44. {
  45. CTK_P(ctkVTKAbstractMatrixWidget);
  46. // if there is no transform to show/edit, disable the widget
  47. p->setEnabled(this->Matrix != 0);
  48. if (this->Matrix == 0)
  49. {
  50. p->reset();
  51. return;
  52. }
  53. QVector<double> vector;
  54. //todo: fasten the loop
  55. for (int i=0; i < 4; i++)
  56. {
  57. for (int j=0; j < 4; j++)
  58. {
  59. vector.append(this->Matrix->GetElement(i,j));
  60. }
  61. }
  62. p->setVector( vector );
  63. }
  64. // --------------------------------------------------------------------------
  65. ctkVTKAbstractMatrixWidget::ctkVTKAbstractMatrixWidget(QWidget* parentVariable) : Superclass(parentVariable)
  66. {
  67. CTK_INIT_PRIVATE(ctkVTKAbstractMatrixWidget);
  68. ctk_d()->init();
  69. }
  70. // --------------------------------------------------------------------------
  71. vtkMatrix4x4* ctkVTKAbstractMatrixWidget::matrix()const
  72. {
  73. CTK_D(const ctkVTKAbstractMatrixWidget);
  74. return d->matrix();
  75. }
  76. // --------------------------------------------------------------------------
  77. void ctkVTKAbstractMatrixWidget::setMatrixInternal(vtkMatrix4x4* matrixVariable)
  78. {
  79. CTK_D(ctkVTKAbstractMatrixWidget);
  80. d->setMatrix(matrixVariable);
  81. }