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 <QVTKWidget.h>
31 #include <vtkChartXY.h>
32 
33 class vtkColorTransferFunction;
34 class vtkControlPointsItem;
35 class vtkLookupTable;
36 class vtkPiecewiseFunction;
37 
39 class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKScalarsToColorsView
40  : public ctkVTKChartView
41 {
42  Q_OBJECT
46  Q_PROPERTY(bool bordersVisible READ areBordersVisible WRITE setBordersVisible)
47 
48 public:
50  ctkVTKScalarsToColorsView(QWidget* parent = 0);
51  virtual ~ctkVTKScalarsToColorsView();
52 
53  virtual void addPlot(vtkPlot* plot);
54 
55  vtkPlot* addLookupTable(vtkLookupTable* lut);
56  vtkPlot* addColorTransferFunction(vtkColorTransferFunction* colorTF, bool editable = true);
57  vtkPlot* addOpacityFunction(vtkPiecewiseFunction* opacityTF, bool editable = true);
58  vtkPlot* addCompositeFunction(vtkColorTransferFunction* colorTF,
59  vtkPiecewiseFunction* opacityTF,
60  bool colorTFEditable = true,
61  bool opacityTFEditable = true);
62  vtkPlot* addPiecewiseFunction(vtkPiecewiseFunction* piecewiseTF, bool editable = true);
63 
64  vtkPlot* addColorTransferFunctionControlPoints(vtkColorTransferFunction* colorTF);
65  vtkPlot* addOpacityFunctionControlPoints(vtkPiecewiseFunction* opacityTF);
66  vtkPlot* addCompositeFunctionControlPoints(vtkColorTransferFunction* colorTF,
67  vtkPiecewiseFunction* opacityTF);
68  vtkPlot* addPiecewiseFunctionControlPoints(vtkPiecewiseFunction* piecewiseTF);
69 
70  QList<vtkPlot*> plots()const;
71  template<class T>
72  QList<T*> plots()const;
73  QList<vtkControlPointsItem*> controlPointsItems()const;
74  QList<vtkPlot*> lookupTablePlots()const;
75  QList<vtkPlot*> lookupTablePlots(vtkLookupTable* lut)const;
76  QList<vtkPlot*> colorTransferFunctionPlots()const;
77  QList<vtkPlot*> colorTransferFunctionPlots(vtkColorTransferFunction* colorTF)const;
78  QList<vtkPlot*> opacityFunctionPlots()const;
79  QList<vtkPlot*> opacityFunctionPlots(vtkPiecewiseFunction* opacityTF)const;
80 
81  void setLookuptTableToPlots(vtkLookupTable* lut);
82  void setColorTransferFunctionToPlots(vtkColorTransferFunction* colorTF);
83  void setOpacityFunctionToPlots(vtkPiecewiseFunction* opacityTF);
84  void setPiecewiseFunctionToPlots(vtkPiecewiseFunction* piecewiseTF);
85 
86  bool areBordersVisible()const;
87  void setBordersVisible(bool show);
88 
89  void validBounds(double bounds[4])const;
90  void setValidBounds(double bounds[4]);
91 
92  void setPlotsUserBounds(double* bounds);
93 
95  virtual void boundAxesToChartBounds();
96 
97 public Q_SLOTS:
98  void editPoint(vtkObject* plot, void * pointId);
99 
102  void moveAllPoints(double xOffset, double yOffset = 0.,
103  bool dontMoveFirstAndLast = false);
104 
109  void spreadAllPoints(double factor = 1.,
110  bool dontMoveFirstAndLast = false);
111 
112 protected Q_SLOTS:
113  void onBoundsChanged();
114 
115 protected:
116  QScopedPointer<ctkVTKScalarsToColorsViewPrivate> d_ptr;
117 
118 private:
119  Q_DECLARE_PRIVATE(ctkVTKScalarsToColorsView);
120  Q_DISABLE_COPY(ctkVTKScalarsToColorsView);
121 };
122 
123 // ----------------------------------------------------------------------------
124 template<class T>
126 {
127  QList<T*> res;
128  const vtkIdType count = this->chart()->GetNumberOfPlots();
129  for(vtkIdType i = 0; i < count; ++i)
130  {
131  vtkPlot* plot = this->chart()->GetPlot(i);
132  if (T::SafeDownCast(plot) != 0)
133  {
134  res << T::SafeDownCast(plot);
135  }
136  }
137  return res;
138 }
139 
140 
141 #endif
QList< vtkPlot * > plots() const
virtual Q_INVOKABLE void addPlot(vtkPlot *plot)
Q_INVOKABLE vtkChartXY * chart() const
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
QScopedPointer< ctkVTKScalarsToColorsViewPrivate > d_ptr