1 /* This source file is part of the Avogadro project.
2    It is released under the 3-Clause BSD License, see "LICENSE". */
3 
4 #ifndef tomvizvtkChartHistogramColorOpacityEditor_h
5 #define tomvizvtkChartHistogramColorOpacityEditor_h
6 
7 #include <vtkAbstractContextItem.h>
8 #include <vtkNew.h>
9 
10 class vtkAxis;
11 class vtkChartHistogram;
12 class vtkChartXY;
13 class vtkColorTransferControlPointsItem;
14 class vtkColorTransferFunction;
15 class vtkColorTransferFunctionItem;
16 class vtkPiecewiseFunction;
17 class vtkScalarsToColors;
18 class vtkTable;
19 
20 // This class is a chart that combines a histogram from a data set
21 // a color bar editor, and an opacity editor.
22 class vtkChartHistogramColorOpacityEditor : public vtkAbstractContextItem
23 {
24 public:
25   vtkTypeMacro(
26     vtkChartHistogramColorOpacityEditor,
27     vtkAbstractContextItem) static vtkChartHistogramColorOpacityEditor* New();
28 
29   // Set the input data.
30   void SetHistogramInputData(vtkTable* table, const char* xAxisColumn,
31                              const char* yAxisColumn);
32 
33   // Set the lookup table.
34   void SetColorTransferFunction(vtkColorTransferFunction* lut);
35 
36   // Enable or disable scalar visibility.
37   virtual void SetScalarVisibility(bool visible);
38 
39   // Set the name of the array by which the histogram should be colored.
40   virtual void SelectColorArray(const char* arrayName);
41 
42   // Set the opacity function.
43   virtual void SetOpacityFunction(vtkPiecewiseFunction* opacityFunction);
44 
45   // Get an axis from the histogram chart.
46   vtkAxis* GetHistogramAxis(int axis);
47 
48   // Get the color of the current color control point. Returns true if there
49   // is a currently selected control point, false otherwise.
50   bool GetCurrentControlPointColor(double rgb[3]);
51 
52   // Set the color of the current color control point.
53   void SetCurrentControlPointColor(const double rgb[3]);
54 
55   // Get the current contour value
56   double GetContourValue();
57 
58   // Set the DPI
59   void SetDPI(int);
60 
61   // Paint event for the editor.
62   virtual bool Paint(vtkContext2D* painter) override;
63 
64 protected:
65   // This provides the histogram, contour value marker, and opacity editor.
66   vtkNew<vtkChartHistogram> HistogramChart;
67 
68   // This is used for the color transfer function editor.
69   vtkNew<vtkChartXY> ColorTransferFunctionChart;
70 
71   // Controls for color transfer function editor.
72   vtkNew<vtkColorTransferControlPointsItem> ColorTransferControlPointsItem;
73 
74   // Display of color transfer function.
75   vtkNew<vtkColorTransferFunctionItem> ColorTransferFunctionItem;
76 
77 private:
78   vtkChartHistogramColorOpacityEditor();
79   ~vtkChartHistogramColorOpacityEditor() override;
80 
81   class PIMPL;
82   PIMPL* Private;
83 
84   float Borders[4];
85 };
86 
87 #endif // tomvizvtkChartHistogramColorOpacityEditor_h
88