ctkVTKChartView.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 __ctkVTKChartView_h
  15. #define __ctkVTKChartView_h
  16. // CTK includes
  17. #include <ctkVTKObject.h>
  18. #include "ctkVisualizationVTKWidgetsExport.h"
  19. class ctkVTKChartViewPrivate;
  20. // VTK includes
  21. #include <QVTKWidget.h>
  22. class vtkChartXY;
  23. class vtkContextScene;
  24. class vtkPlot;
  25. /// \ingroup Visualization_VTK_Widgets
  26. class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKChartView : public QVTKWidget
  27. {
  28. Q_OBJECT
  29. QVTK_OBJECT
  30. Q_PROPERTY(QString title READ title WRITE setTitle)
  31. public:
  32. typedef QVTKWidget Superclass;
  33. ctkVTKChartView(QWidget* parent = 0);
  34. virtual ~ctkVTKChartView();
  35. /// Generic function to add a custom plot. \a plot is added into the chart
  36. /// Emit the plotAdded(vtkPlot*) signal.
  37. Q_INVOKABLE virtual void addPlot(vtkPlot* plot);
  38. /// Remove the plot from the chart. Do nothing if plot is not in the chart.
  39. /// Emit the plotRemoved(vtkPlot*) signal.
  40. Q_INVOKABLE virtual void removePlot(vtkPlot* plot);
  41. /// Return the id of the plot in the chart.
  42. /// -1 if the plot is not found in the chart
  43. Q_INVOKABLE vtkIdType plotIndex(vtkPlot* plot);
  44. /// Utility function that returns the view chart. It can be used for customizing
  45. /// the chart display options (axes, legend...)
  46. Q_INVOKABLE vtkChartXY* chart()const;
  47. Q_INVOKABLE vtkContextScene* scene()const;
  48. /// Title that appears inside the view
  49. QString title()const;
  50. void setTitle(const QString& title);
  51. /// Return the chart extent for the 4 chart axes.
  52. /// extent must be an array of 8 doubles
  53. /// The current extent is the visible area on the chart.
  54. /// it is equivalent to the Minimum/Maximum of the axes
  55. void chartExtent(double bounds[8])const;
  56. /// Return the chart bounds for the 4 chart axes.
  57. /// bounds must be an array of 8 doubles.
  58. /// If no bounds is provided by the user, compute the bounds for the 4 chart
  59. /// axes from the vtkPlots bounds.
  60. void chartBounds(double bounds[8])const;
  61. void setChartUserBounds(double* bounds);
  62. void chartUserBounds(double* bounds)const;
  63. public Q_SLOTS:
  64. /// Remove all the plots from the chart
  65. void removeAllPlots();
  66. ///
  67. virtual void setAxesToChartBounds();
  68. virtual void boundAxesToChartBounds();
  69. Q_SIGNALS:
  70. void plotAdded(vtkPlot* plot);
  71. void plotRemoved(vtkPlot* plot);
  72. /// Fired anytime the bound of a plot modifies the overal bounds
  73. void boundsChanged();
  74. /// Fired anytime an axis is modified.
  75. void extentChanged();
  76. protected:
  77. QScopedPointer<ctkVTKChartViewPrivate> d_ptr;
  78. virtual void mouseDoubleClickEvent(QMouseEvent* event);
  79. virtual void onChartUpdated();
  80. void chartBoundsToPlotBounds(double bounds[8], double plotBounds[4])const;
  81. private:
  82. Q_DECLARE_PRIVATE(ctkVTKChartView);
  83. Q_DISABLE_COPY(ctkVTKChartView);
  84. };
  85. #endif