1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkScalarsToColorsItem.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 /**
17  * @class   vtkScalarsToColorsItem
18  * @brief   Abstract class for ScalarsToColors items.
19  *
20  * vtkScalarsToColorsItem implements item bounds and painting for inherited
21  * classes that provide a texture (ComputeTexture()) and optionally a shape
22  * @sa
23  * vtkControlPointsItem
24  * vtkLookupTableItem
25  * vtkColorTransferFunctionItem
26  * vtkCompositeTransferFunctionItem
27  * vtkPiecewiseItemFunctionItem
28 */
29 
30 #ifndef vtkScalarsToColorsItem_h
31 #define vtkScalarsToColorsItem_h
32 
33 #include "vtkChartsCoreModule.h" // For export macro
34 #include "vtkPlot.h"
35 
36 class vtkCallbackCommand;
37 class vtkImageData;
38 class vtkPoints2D;
39 
40 class VTKCHARTSCORE_EXPORT vtkScalarsToColorsItem: public vtkPlot
41 {
42 public:
43   vtkTypeMacro(vtkScalarsToColorsItem, vtkPlot);
44   void PrintSelf(ostream &os, vtkIndent indent) override;
45 
46   /**
47    * Bounds of the item, use the UserBounds if valid otherwise compute
48    * the bounds of the item (based on the transfer function range).
49    */
50   void GetBounds(double bounds[4]) override;
51 
52   //@{
53   /**
54    * Set custom bounds, except if bounds are invalid, bounds will be
55    * automatically computed based on the range of the control points
56    * Invalid bounds by default.
57    */
58   vtkSetVector4Macro(UserBounds, double);
59   vtkGetVector4Macro(UserBounds, double)
60   //@}
61 
62   /**
63    * Paint the texture into a rectangle defined by the bounds. If
64    * MaskAboveCurve is true and a shape has been provided by a subclass, it
65    * draws the texture into the shape
66    */
67   bool Paint(vtkContext2D *painter) override;
68 
69   //@{
70   /**
71    * Get a pointer to the vtkPen object that controls the drawing of the edge
72    * of the shape if any.
73    * PolyLinePen type is vtkPen::NO_PEN by default.
74    */
75   vtkGetObjectMacro(PolyLinePen, vtkPen);
76   //@}
77 
78   //@{
79   /**
80    * Don't fill in the part above the transfer function.
81    * If true texture is not visible above the shape provided by subclasses,
82    * otherwise the whole rectangle defined by the bounds is filled with the
83    * transfer function.
84    * Note: only 2D transfer functions (RGB tf + alpha tf ) support the feature.
85    */
86   vtkSetMacro(MaskAboveCurve, bool);
87   vtkGetMacro(MaskAboveCurve, bool);
88   //@}
89 
90 protected:
91   vtkScalarsToColorsItem();
92   ~vtkScalarsToColorsItem() override;
93 
94   /**
95    * Bounds of the item, by default (0, 1, 0, 1) but it depends on the
96    * range of the ScalarsToColors function.
97    * Need to be reimplemented by subclasses if the range is != [0,1]
98    */
99   virtual void ComputeBounds(double* bounds);
100 
101   /**
102    * Need to be reimplemented by subclasses, ComputeTexture() is called at
103    * paint time if the texture is not up to date compared to vtkScalarsToColorsItem
104    * Return false if no texture is generated.
105    */
106   virtual void ComputeTexture() = 0;
107 
108   vtkGetMacro(TextureWidth, int);
109 
110   void TransformDataToScreen(const double dataX, const double dataY,
111                              double &screenX, double &screenY);
112   void TransformScreenToData(const double screenX, const double screenY,
113                              double &dataX, double &dataY);
114 
115   //@{
116   /**
117    * Called whenever the ScalarsToColors function(s) is modified. It internally
118    * calls Modified(). Can be reimplemented by subclasses
119    */
120   virtual void ScalarsToColorsModified(vtkObject* caller, unsigned long eid, void* calldata);
121   static void OnScalarsToColorsModified(vtkObject* caller, unsigned long eid, void *clientdata, void* calldata);
122   //@}
123 
124   double              UserBounds[4];
125 
126   int                 TextureWidth;
127   vtkImageData*       Texture;
128   bool                Interpolate;
129   vtkPoints2D*        Shape;
130   vtkCallbackCommand* Callback;
131 
132   vtkPen*             PolyLinePen;
133   bool                MaskAboveCurve;
134 private:
135   vtkScalarsToColorsItem(const vtkScalarsToColorsItem &) = delete;
136   void operator=(const vtkScalarsToColorsItem &) = delete;
137 };
138 
139 #endif
140