ctkVTKVolumePropertyWidget.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 <QDebug>
  16. // CTK includes
  17. #include "ctkLogger.h"
  18. #include "ctkVTKScalarsToColorsView.h"
  19. #include "ctkVTKVolumePropertyWidget.h"
  20. #include "ui_ctkVTKVolumePropertyWidget.h"
  21. // VTK includes
  22. #include <vtkColorTransferControlPointsItem.h>
  23. #include <vtkColorTransferFunction.h>
  24. #include <vtkColorTransferFunctionItem.h>
  25. #include <vtkCompositeControlPointsItem.h>
  26. #include <vtkCompositeTransferFunctionItem.h>
  27. #include <vtkContextScene.h>
  28. #include <vtkLookupTable.h>
  29. #include <vtkLookupTableItem.h>
  30. #include <vtkPiecewiseControlPointsItem.h>
  31. #include <vtkPiecewiseFunction.h>
  32. #include <vtkPiecewiseFunctionItem.h>
  33. #include <vtkVolumeProperty.h>
  34. //----------------------------------------------------------------------------
  35. static ctkLogger logger("org.commontk.visualization.vtk.widgets.ctkVTKVolumePropertyWidget");
  36. //----------------------------------------------------------------------------
  37. class ctkVTKVolumePropertyWidgetPrivate:
  38. public Ui_ctkVTKVolumePropertyWidget
  39. {
  40. Q_DECLARE_PUBLIC(ctkVTKVolumePropertyWidget);
  41. protected:
  42. ctkVTKVolumePropertyWidget* const q_ptr;
  43. public:
  44. ctkVTKVolumePropertyWidgetPrivate(ctkVTKVolumePropertyWidget& object);
  45. void setupUi(QWidget* widget);
  46. vtkVolumeProperty* VolumeProperty;
  47. };
  48. // ----------------------------------------------------------------------------
  49. // ctkVTKVolumePropertyWidgetPrivate methods
  50. // ----------------------------------------------------------------------------
  51. ctkVTKVolumePropertyWidgetPrivate::ctkVTKVolumePropertyWidgetPrivate(
  52. ctkVTKVolumePropertyWidget& object)
  53. : q_ptr(&object)
  54. {
  55. this->VolumeProperty = 0;
  56. }
  57. // ----------------------------------------------------------------------------
  58. void ctkVTKVolumePropertyWidgetPrivate::setupUi(QWidget* widget)
  59. {
  60. //Q_Q(ctkVTKVolumePropertyWidget);
  61. this->Ui_ctkVTKVolumePropertyWidget::setupUi(widget);
  62. this->ScalarOpacityWidget->view()->addCompositeFunction(0, 0, false, true);
  63. this->ScalarColorWidget->view()->addColorTransferFunction(0);
  64. this->GradientWidget->view()->addPiecewiseFunction(0);
  65. this->GradientGroupBox->setCollapsed(true);
  66. this->AdvancedGroupBox->setCollapsed(true);
  67. }
  68. // ----------------------------------------------------------------------------
  69. // ctkVTKVolumePropertyWidget methods
  70. // ----------------------------------------------------------------------------
  71. ctkVTKVolumePropertyWidget::ctkVTKVolumePropertyWidget(QWidget* parentWidget)
  72. :QWidget(parentWidget)
  73. , d_ptr(new ctkVTKVolumePropertyWidgetPrivate(*this))
  74. {
  75. Q_D(ctkVTKVolumePropertyWidget);
  76. d->setupUi(this);
  77. }
  78. // ----------------------------------------------------------------------------
  79. ctkVTKVolumePropertyWidget::~ctkVTKVolumePropertyWidget()
  80. {
  81. }
  82. // ----------------------------------------------------------------------------
  83. vtkVolumeProperty* ctkVTKVolumePropertyWidget::volumeProperty()const
  84. {
  85. Q_D(const ctkVTKVolumePropertyWidget);
  86. return d->VolumeProperty;
  87. }
  88. // ----------------------------------------------------------------------------
  89. void ctkVTKVolumePropertyWidget
  90. ::setVolumeProperty(vtkVolumeProperty* newVolumeProperty)
  91. {
  92. Q_D(ctkVTKVolumePropertyWidget);
  93. this->qvtkReconnect(d->VolumeProperty, newVolumeProperty, vtkCommand::ModifiedEvent,
  94. this, SLOT(updateFromVolumeProperty()));
  95. d->VolumeProperty = newVolumeProperty;
  96. this->updateFromVolumeProperty();
  97. }
  98. // ----------------------------------------------------------------------------
  99. void ctkVTKVolumePropertyWidget::updateFromVolumeProperty()
  100. {
  101. Q_D(ctkVTKVolumePropertyWidget);
  102. vtkColorTransferFunction* colorTransferFunction = 0;
  103. vtkPiecewiseFunction* opacityFunction = 0;
  104. vtkPiecewiseFunction* gradientFunction = 0;
  105. if (d->VolumeProperty)
  106. {
  107. colorTransferFunction =
  108. d->VolumeProperty->GetRGBTransferFunction()->GetSize() ?
  109. d->VolumeProperty->GetRGBTransferFunction() : 0;
  110. opacityFunction =
  111. d->VolumeProperty->GetScalarOpacity()->GetSize() ?
  112. d->VolumeProperty->GetScalarOpacity() : 0;
  113. gradientFunction =
  114. d->VolumeProperty->GetGradientOpacity()->GetSize() ?
  115. d->VolumeProperty->GetGradientOpacity() : 0;
  116. }
  117. d->ScalarOpacityWidget->view()->setOpacityFunctionToPlots(opacityFunction);
  118. d->ScalarOpacityWidget->view()->setColorTransferFunctionToPlots(colorTransferFunction);
  119. d->ScalarColorWidget->view()->setColorTransferFunctionToPlots(colorTransferFunction);
  120. d->GradientWidget->view()->setPiecewiseFunctionToPlots(gradientFunction);
  121. if (d->VolumeProperty)
  122. {
  123. d->MaterialPropertyLabel->setAmbient(d->VolumeProperty->GetAmbient());
  124. d->MaterialPropertyLabel->setDiffuse(d->VolumeProperty->GetDiffuse());
  125. d->MaterialPropertyLabel->setSpecular(d->VolumeProperty->GetSpecular());
  126. d->MaterialPropertyLabel->setSpecularPower(d->VolumeProperty->GetSpecularPower());
  127. d->InterpolationComboBox->setCurrentIndex(
  128. d->VolumeProperty->GetInterpolationType() == VTK_NEAREST_INTERPOLATION ? 0 : 1);
  129. }
  130. }