ctkVTKScalarsToColorsView.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #ifndef __ctkVTKScalarsToColorsView_h
  15. #define __ctkVTKScalarsToColorsView_h
  16. // CTK includes
  17. #include "ctkVTKChartView.h"
  18. #include "ctkVTKObject.h"
  19. class ctkVTKScalarsToColorsViewPrivate;
  20. // VTK includes
  21. #include <QVTKWidget.h>
  22. #include <vtkChartXY.h>
  23. class vtkColorTransferFunction;
  24. class vtkControlPointsItem;
  25. class vtkLookupTable;
  26. class vtkPiecewiseFunction;
  27. /// \ingroup Visualization_VTK_Widgets
  28. class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKScalarsToColorsView
  29. : public ctkVTKChartView
  30. {
  31. Q_OBJECT
  32. QVTK_OBJECT
  33. /// Add an empty space around the view to give space to the corner control
  34. /// points. False by default
  35. Q_PROPERTY(bool bordersVisible READ areBordersVisible WRITE setBordersVisible)
  36. public:
  37. typedef ctkVTKChartView Superclass;
  38. ctkVTKScalarsToColorsView(QWidget* parent = 0);
  39. virtual ~ctkVTKScalarsToColorsView();
  40. virtual void addPlot(vtkPlot* plot);
  41. vtkPlot* addLookupTable(vtkLookupTable* lut);
  42. Q_INVOKABLE vtkPlot* addColorTransferFunction(vtkColorTransferFunction* colorTF, bool editable = true);
  43. vtkPlot* addOpacityFunction(vtkPiecewiseFunction* opacityTF, bool editable = true);
  44. vtkPlot* addCompositeFunction(vtkColorTransferFunction* colorTF,
  45. vtkPiecewiseFunction* opacityTF,
  46. bool colorTFEditable = true,
  47. bool opacityTFEditable = true);
  48. vtkPlot* addPiecewiseFunction(vtkPiecewiseFunction* piecewiseTF, bool editable = true);
  49. vtkPlot* addColorTransferFunctionControlPoints(vtkColorTransferFunction* colorTF);
  50. vtkPlot* addOpacityFunctionControlPoints(vtkPiecewiseFunction* opacityTF);
  51. vtkPlot* addCompositeFunctionControlPoints(vtkColorTransferFunction* colorTF,
  52. vtkPiecewiseFunction* opacityTF);
  53. vtkPlot* addPiecewiseFunctionControlPoints(vtkPiecewiseFunction* piecewiseTF);
  54. QList<vtkPlot*> plots()const;
  55. template<class T>
  56. QList<T*> plots()const;
  57. QList<vtkControlPointsItem*> controlPointsItems()const;
  58. QList<vtkPlot*> lookupTablePlots()const;
  59. QList<vtkPlot*> lookupTablePlots(vtkLookupTable* lut)const;
  60. QList<vtkPlot*> colorTransferFunctionPlots()const;
  61. QList<vtkPlot*> colorTransferFunctionPlots(vtkColorTransferFunction* colorTF)const;
  62. QList<vtkPlot*> opacityFunctionPlots()const;
  63. QList<vtkPlot*> opacityFunctionPlots(vtkPiecewiseFunction* opacityTF)const;
  64. void setLookuptTableToPlots(vtkLookupTable* lut);
  65. void setColorTransferFunctionToPlots(vtkColorTransferFunction* colorTF);
  66. void setOpacityFunctionToPlots(vtkPiecewiseFunction* opacityTF);
  67. void setPiecewiseFunctionToPlots(vtkPiecewiseFunction* piecewiseTF);
  68. bool areBordersVisible()const;
  69. void setBordersVisible(bool show);
  70. void validBounds(double bounds[4])const;
  71. void setValidBounds(double bounds[4]);
  72. void setPlotsUserBounds(double* bounds);
  73. /// Reimplemented to set the bounds to the plots as well
  74. virtual void boundAxesToChartBounds();
  75. public Q_SLOTS:
  76. void editPoint(vtkObject* plot, void * pointId);
  77. /// Move all the control points by a given offset.
  78. /// \sa vtkControlPoints::movePoints()
  79. void moveAllPoints(double xOffset, double yOffset = 0.,
  80. bool dontMoveFirstAndLast = false);
  81. /// Spread all the control points by a given offset.
  82. /// A value >0 will space the control points, a value <0. will contract
  83. /// them.
  84. /// \sa vtkControlPoints::spreadPoints()
  85. void spreadAllPoints(double factor = 1.,
  86. bool dontMoveFirstAndLast = false);
  87. protected Q_SLOTS:
  88. void onBoundsChanged();
  89. protected:
  90. QScopedPointer<ctkVTKScalarsToColorsViewPrivate> d_ptr;
  91. private:
  92. Q_DECLARE_PRIVATE(ctkVTKScalarsToColorsView);
  93. Q_DISABLE_COPY(ctkVTKScalarsToColorsView);
  94. };
  95. // ----------------------------------------------------------------------------
  96. template<class T>
  97. QList<T*> ctkVTKScalarsToColorsView::plots()const
  98. {
  99. QList<T*> res;
  100. const vtkIdType count = this->chart()->GetNumberOfPlots();
  101. for(vtkIdType i = 0; i < count; ++i)
  102. {
  103. vtkPlot* plot = this->chart()->GetPlot(i);
  104. if (T::SafeDownCast(plot) != 0)
  105. {
  106. res << T::SafeDownCast(plot);
  107. }
  108. }
  109. return res;
  110. }
  111. #endif