ctkVTKScalarsToColorsView.h 5.0 KB

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