CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkVTKScalarsToColorsView.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkVTKScalarsToColorsView_h
22 #define __ctkVTKScalarsToColorsView_h
23 
24 // CTK includes
25 #include "ctkVTKChartView.h"
26 #include "ctkVTKObject.h"
27 class ctkVTKScalarsToColorsViewPrivate;
28 
29 // VTK includes
30 #include <vtkChartXY.h>
31 
32 class vtkColorTransferFunction;
33 class vtkControlPointsItem;
34 class vtkLookupTable;
35 class vtkPiecewiseFunction;
36 
38 class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKScalarsToColorsView
39  : public ctkVTKChartView
40 {
41  Q_OBJECT
45  Q_PROPERTY(bool bordersVisible READ areBordersVisible WRITE setBordersVisible)
46 
47 public:
49  ctkVTKScalarsToColorsView(QWidget* parent = 0);
50  virtual ~ctkVTKScalarsToColorsView();
51 
52  virtual void addPlot(vtkPlot* plot);
53 
54  vtkPlot* addLookupTable(vtkLookupTable* lut);
55  Q_INVOKABLE vtkPlot* addColorTransferFunction(vtkColorTransferFunction* colorTF, bool editable = true);
56  vtkPlot* addOpacityFunction(vtkPiecewiseFunction* opacityTF, bool editable = true);
57  vtkPlot* addCompositeFunction(vtkColorTransferFunction* colorTF,
58  vtkPiecewiseFunction* opacityTF,
59  bool colorTFEditable = true,
60  bool opacityTFEditable = true);
61  vtkPlot* addPiecewiseFunction(vtkPiecewiseFunction* piecewiseTF, bool editable = true);
62 
63  vtkPlot* addColorTransferFunctionControlPoints(vtkColorTransferFunction* colorTF);
64  vtkPlot* addOpacityFunctionControlPoints(vtkPiecewiseFunction* opacityTF);
65  vtkPlot* addCompositeFunctionControlPoints(vtkColorTransferFunction* colorTF,
66  vtkPiecewiseFunction* opacityTF);
67  vtkPlot* addPiecewiseFunctionControlPoints(vtkPiecewiseFunction* piecewiseTF);
68 
69  QList<vtkPlot*> plots()const;
70  template<class T>
71  QList<T*> plots()const;
72  QList<vtkControlPointsItem*> controlPointsItems()const;
73  QList<vtkPlot*> lookupTablePlots()const;
74  QList<vtkPlot*> lookupTablePlots(vtkLookupTable* lut)const;
75  QList<vtkPlot*> colorTransferFunctionPlots()const;
76  QList<vtkPlot*> colorTransferFunctionPlots(vtkColorTransferFunction* colorTF)const;
77  QList<vtkPlot*> opacityFunctionPlots()const;
78  QList<vtkPlot*> opacityFunctionPlots(vtkPiecewiseFunction* opacityTF)const;
79 
80  void setLookuptTableToPlots(vtkLookupTable* lut);
81  void setColorTransferFunctionToPlots(vtkColorTransferFunction* colorTF);
82  void setOpacityFunctionToPlots(vtkPiecewiseFunction* opacityTF);
83  void setPiecewiseFunctionToPlots(vtkPiecewiseFunction* piecewiseTF);
84 
85  bool areBordersVisible()const;
86  void setBordersVisible(bool show);
87 
88  void validBounds(double bounds[4])const;
89  void setValidBounds(double bounds[4]);
90 
91  void setPlotsUserBounds(double* bounds);
92 
94  virtual void boundAxesToChartBounds();
95 
96 public Q_SLOTS:
97  void editPoint(vtkObject* plot, void * pointId);
98 
101  void moveAllPoints(double xOffset, double yOffset = 0.,
102  bool dontMoveFirstAndLast = false);
103 
108  void spreadAllPoints(double factor = 1.,
109  bool dontMoveFirstAndLast = false);
110 
111 protected Q_SLOTS:
112  void onBoundsChanged();
113 
114 protected:
115  QScopedPointer<ctkVTKScalarsToColorsViewPrivate> d_ptr;
116 
117 private:
118  Q_DECLARE_PRIVATE(ctkVTKScalarsToColorsView);
119  Q_DISABLE_COPY(ctkVTKScalarsToColorsView);
120 };
121 
122 // ----------------------------------------------------------------------------
123 template<class T>
125 {
126  QList<T*> res;
127  const vtkIdType count = this->chart()->GetNumberOfPlots();
128  for(vtkIdType i = 0; i < count; ++i)
129  {
130  vtkPlot* plot = this->chart()->GetPlot(i);
131  if (T::SafeDownCast(plot) != 0)
132  {
133  res << T::SafeDownCast(plot);
134  }
135  }
136  return res;
137 }
138 
139 
140 #endif
Q_INVOKABLE vtkChartXY * chart() const
virtual Q_INVOKABLE void addPlot(vtkPlot *plot)
virtual void boundAxesToChartBounds()
#define QVTK_OBJECT
Define VTK/Qt event/slot connection utility methods. It is a convenient macro that declares and defin...
Definition: ctkVTKObject.h:222
QList< vtkPlot * > plots() const
QScopedPointer< ctkVTKScalarsToColorsViewPrivate > d_ptr