ctkVTKScalarsToColorsWidget.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 __ctkVTKScalarsToColorsWidget_h
  15. #define __ctkVTKScalarsToColorsWidget_h
  16. //Qt includes
  17. #include <QWidget>
  18. // CTK includes
  19. #include <ctkVTKObject.h>
  20. #include "ctkVisualizationVTKWidgetsExport.h"
  21. class ctkVTKScalarsToColorsView;
  22. class ctkVTKScalarsToColorsWidgetPrivate;
  23. // VTK includes
  24. class vtkControlPointsItem;
  25. class vtkPlot;
  26. /// \ingroup Visualization_VTK_Widgets
  27. ///
  28. /// This widget includes a ctkVTKScalarsToColorsView and a "top widget" to display and update its properties.
  29. ///
  30. /// Features are:
  31. /// * vertical and horizontal scrollbars (if needed, visible by default)
  32. /// * a "top widget" including selected point index, its coordinate and color. An expand button allows to access
  33. /// advanced properties like mid point and sharpness.
  34. /// * if a piecewise or composite function are added to the view, the opacity is available in the "top widget" advanced properties.
  35. /// * color associated with points can be updated in place (editable by default).
  36. /// * support customization of widget shown in the top-left corner. See addExtraWidget().
  37. /// * visibility of the "top widgets" can easily be updated.
  38. ///
  39. /// Observing vtkControlPointsItem allows to be notified of point selection or
  40. /// point update:
  41. /// * event vtkControlPointsItem::CurrentPointChangedEvent is invoked each time a point is selected. Associated
  42. /// call data is the point index.
  43. /// * event vtkCommand::ModifiedEvent is invoked each time a point is updated.
  44. ///
  45. class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKScalarsToColorsWidget : public QWidget
  46. {
  47. Q_OBJECT
  48. QVTK_OBJECT
  49. Q_PROPERTY(bool horizontalSliderVisible READ isHorizontalSliderVisible WRITE setHorizontalSliderVisible)
  50. Q_PROPERTY(bool verticalSliderVisible READ isVerticalSliderVisible WRITE setVerticalSliderVisible)
  51. Q_PROPERTY(bool editColors READ editColors WRITE setEditColors)
  52. Q_PROPERTY(bool areTopWidgetsVisible READ areTopWidgetsVisible WRITE setTopWidgetsVisible)
  53. public:
  54. ctkVTKScalarsToColorsWidget(QWidget* parent = 0);
  55. virtual ~ctkVTKScalarsToColorsWidget();
  56. ctkVTKScalarsToColorsView* view()const;
  57. vtkControlPointsItem* currentControlPointsItem()const;
  58. bool isHorizontalSliderVisible()const;
  59. void setHorizontalSliderVisible(bool visible);
  60. bool isVerticalSliderVisible()const;
  61. void setVerticalSliderVisible(bool visible);
  62. bool editColors()const;
  63. void setEditColors(bool edit);
  64. void xRange(double* range)const;
  65. void yRange(double* range)const;
  66. /// Hide all widgets displayed above the color view.
  67. ///
  68. /// This function internally keeps track of the selected visibility state
  69. /// by setting a "TopWidgetsVisible" property. This means that:
  70. /// (1) widgets for editing point coordinate and color are
  71. /// not shown in the "top widgets" when a point is selected or modified.
  72. /// (2) widgets added using addExtraWidget() are explicitly hidden if it applies.
  73. bool areTopWidgetsVisible()const;
  74. void setTopWidgetsVisible(bool visible);
  75. /// Return the top-left corner widget if any.
  76. ///
  77. /// \sa addExtraWidget()
  78. QWidgetList extraWidgets()const;
  79. /// Add a widget in the top-left corner.
  80. ///
  81. /// ctkVTKScalarsToColorsWidget takes ownership of the widget.
  82. ///
  83. /// \sa extraWidgets()
  84. void addExtraWidget(QWidget* extraWidget);
  85. public Q_SLOTS:
  86. void setCurrentControlPointsItem(vtkControlPointsItem* item);
  87. void setCurrentPoint(int pointId);
  88. void setXRange(double min, double max);
  89. void setYRange(double min, double max);
  90. void resetRange();
  91. Q_SIGNALS:
  92. /// Be carefull, axesModified() can be fired inside the Render() function
  93. /// of the view. You might want to connect the slot using Qt::QueuedConnection
  94. void axesModified();
  95. protected Q_SLOTS:
  96. void onPlotAdded(vtkPlot*);
  97. void onBoundsChanged();
  98. void setCurrentPoint(vtkObject* controlPointsItem, void* pointId);
  99. void updateNumberOfPoints();
  100. void updateCurrentPoint();
  101. void onCurrentPointChanged(int pointId);
  102. void onColorChanged(const QColor& color);
  103. void onXChanged(double x);
  104. void onOpacityChanged(double opacity);
  105. void onMidPointChanged(double midPoint);
  106. void onSharpnessChanged(double sharpness);
  107. void onAxesModified();
  108. void restorePalette();
  109. void onExpandButton(bool state);
  110. protected:
  111. QScopedPointer<ctkVTKScalarsToColorsWidgetPrivate> d_ptr;
  112. private:
  113. Q_DECLARE_PRIVATE(ctkVTKScalarsToColorsWidget);
  114. Q_DISABLE_COPY(ctkVTKScalarsToColorsWidget);
  115. };
  116. #endif