1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkApplyColors.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   Copyright 2008 Sandia Corporation.
17   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18   the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
20 /**
21  * @class   vtkApplyColors
22  * @brief   apply colors to a data set.
23  *
24  *
25  * vtkApplyColors performs a coloring of the dataset using default colors,
26  * lookup tables, annotations, and/or a selection. The output is a
27  * four-component vtkUnsignedCharArray containing RGBA tuples for each
28  * element in the dataset. The first input is the dataset to be colored, which
29  * may be a vtkTable, vtkGraph subclass, or vtkDataSet subclass. The API
30  * of this algorithm refers to "points" and "cells". For vtkGraph, the
31  * "points" refer to the graph vertices and "cells" refer to graph edges.
32  * For vtkTable, "points" refer to table rows. For vtkDataSet subclasses, the
33  * meaning is obvious.
34  *
35  * The second (optional) input is a vtkAnnotationLayers object, which stores
36  * a list of annotation layers, with each layer holding a list of
37  * vtkAnnotation objects. The annotation specifies a subset of data along with
38  * other properties, including color. For annotations with color properties,
39  * this algorithm will use the color to color elements, using a "top one wins"
40  * strategy.
41  *
42  * The third (optional) input is a vtkSelection object, meant for specifying
43  * the current selection. You can control the color of the selection.
44  *
45  * The algorithm takes two input arrays, specified with
46  * SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, name)
47  * and
48  * SetInputArrayToProcess(1, 0, 0, vtkDataObject::FIELD_ASSOCIATION_CELLS, name).
49  * These set the point and cell data arrays to use to color the data with
50  * the associated lookup table. For vtkGraph, vtkTable inputs, you would use
51  * FIELD_ASSOCIATION_VERTICES, FIELD_ASSOCIATION_EDGES, or
52  * FIELD_ASSOCIATION_ROWS as appropriate.
53  *
54  * To use the color array generated here, you should do the following:
55  *
56  *  mapper->SetScalarModeToUseCellFieldData();
57  *  mapper->SelectColorArray("vtkApplyColors color");
58  *  mapper->SetScalarVisibility(true);
59  *
60  * Colors are assigned with the following priorities:
61  * <ol>
62  * <li> If an item is part of the selection, it is colored with that color.
63  * <li> Otherwise, if the item is part of an annotation, it is colored
64  *      with the color of the final (top) annotation in the set of layers.
65  * <li> Otherwise, if the lookup table is used, it is colored using the
66  *      lookup table color for the data value of the element.
67  * <li> Otherwise it will be colored with the default color.
68  * </ol>
69  *
70  * Note: The opacity of an unselected item is defined by the multiplication
71  * of default opacity, lookup table opacity, and annotation opacity, where
72  * opacity is taken as a number from 0 to 1. So items will never be more opaque
73  * than any of these three opacities. Selected items are always given the
74  * selection opacity directly.
75 */
76 
77 #ifndef vtkApplyColors_h
78 #define vtkApplyColors_h
79 
80 #include "vtkViewsInfovisModule.h" // For export macro
81 #include "vtkPassInputTypeAlgorithm.h"
82 
83 class vtkScalarsToColors;
84 class vtkUnsignedCharArray;
85 
86 class VTKVIEWSINFOVIS_EXPORT vtkApplyColors : public vtkPassInputTypeAlgorithm
87 {
88 public:
89   static vtkApplyColors *New();
90   vtkTypeMacro(vtkApplyColors, vtkPassInputTypeAlgorithm);
91   void PrintSelf(ostream& os, vtkIndent indent) override;
92 
93   //@{
94   /**
95    * The lookup table to use for point colors. This is only used if
96    * input array 0 is set and UsePointLookupTable is on.
97    */
98   virtual void SetPointLookupTable(vtkScalarsToColors* lut);
99   vtkGetObjectMacro(PointLookupTable, vtkScalarsToColors);
100   //@}
101 
102   //@{
103   /**
104    * If on, uses the point lookup table to set the colors of unannotated,
105    * unselected elements of the data.
106    */
107   vtkSetMacro(UsePointLookupTable, bool);
108   vtkGetMacro(UsePointLookupTable, bool);
109   vtkBooleanMacro(UsePointLookupTable, bool);
110   //@}
111 
112   //@{
113   /**
114    * If on, uses the range of the data to scale the lookup table range.
115    * Otherwise, uses the range defined in the lookup table.
116    */
117   vtkSetMacro(ScalePointLookupTable, bool);
118   vtkGetMacro(ScalePointLookupTable, bool);
119   vtkBooleanMacro(ScalePointLookupTable, bool);
120   //@}
121 
122   //@{
123   /**
124    * The default point color for all unannotated, unselected elements
125    * of the data. This is used if UsePointLookupTable is off.
126    */
127   vtkSetVector3Macro(DefaultPointColor, double);
128   vtkGetVector3Macro(DefaultPointColor, double);
129   //@}
130 
131   //@{
132   /**
133    * The default point opacity for all unannotated, unselected elements
134    * of the data. This is used if UsePointLookupTable is off.
135    */
136   vtkSetMacro(DefaultPointOpacity, double);
137   vtkGetMacro(DefaultPointOpacity, double);
138   //@}
139 
140   //@{
141   /**
142    * The point color for all selected elements of the data.
143    * This is used if the selection input is available.
144    */
145   vtkSetVector3Macro(SelectedPointColor, double);
146   vtkGetVector3Macro(SelectedPointColor, double);
147   //@}
148 
149   //@{
150   /**
151    * The point opacity for all selected elements of the data.
152    * This is used if the selection input is available.
153    */
154   vtkSetMacro(SelectedPointOpacity, double);
155   vtkGetMacro(SelectedPointOpacity, double);
156   //@}
157 
158   //@{
159   /**
160    * The output array name for the point color RGBA array.
161    * Default is "vtkApplyColors color".
162    */
163   vtkSetStringMacro(PointColorOutputArrayName);
164   vtkGetStringMacro(PointColorOutputArrayName);
165   //@}
166 
167   //@{
168   /**
169    * The lookup table to use for cell colors. This is only used if
170    * input array 1 is set and UseCellLookupTable is on.
171    */
172   virtual void SetCellLookupTable(vtkScalarsToColors* lut);
173   vtkGetObjectMacro(CellLookupTable, vtkScalarsToColors);
174   //@}
175 
176   //@{
177   /**
178    * If on, uses the cell lookup table to set the colors of unannotated,
179    * unselected elements of the data.
180    */
181   vtkSetMacro(UseCellLookupTable, bool);
182   vtkGetMacro(UseCellLookupTable, bool);
183   vtkBooleanMacro(UseCellLookupTable, bool);
184   //@}
185 
186   //@{
187   /**
188    * If on, uses the range of the data to scale the lookup table range.
189    * Otherwise, uses the range defined in the lookup table.
190    */
191   vtkSetMacro(ScaleCellLookupTable, bool);
192   vtkGetMacro(ScaleCellLookupTable, bool);
193   vtkBooleanMacro(ScaleCellLookupTable, bool);
194   //@}
195 
196   //@{
197   /**
198    * The default cell color for all unannotated, unselected elements
199    * of the data. This is used if UseCellLookupTable is off.
200    */
201   vtkSetVector3Macro(DefaultCellColor, double);
202   vtkGetVector3Macro(DefaultCellColor, double);
203   //@}
204 
205   //@{
206   /**
207    * The default cell opacity for all unannotated, unselected elements
208    * of the data. This is used if UseCellLookupTable is off.
209    */
210   vtkSetMacro(DefaultCellOpacity, double);
211   vtkGetMacro(DefaultCellOpacity, double);
212   //@}
213 
214   //@{
215   /**
216    * The cell color for all selected elements of the data.
217    * This is used if the selection input is available.
218    */
219   vtkSetVector3Macro(SelectedCellColor, double);
220   vtkGetVector3Macro(SelectedCellColor, double);
221   //@}
222 
223   //@{
224   /**
225    * The cell opacity for all selected elements of the data.
226    * This is used if the selection input is available.
227    */
228   vtkSetMacro(SelectedCellOpacity, double);
229   vtkGetMacro(SelectedCellOpacity, double);
230   //@}
231 
232   //@{
233   /**
234    * The output array name for the cell color RGBA array.
235    * Default is "vtkApplyColors color".
236    */
237   vtkSetStringMacro(CellColorOutputArrayName);
238   vtkGetStringMacro(CellColorOutputArrayName);
239   //@}
240 
241   //@{
242   /**
243    * Use the annotation to color the current annotation
244    * (i.e. the current selection). Otherwise use the selection
245    * color attributes of this filter.
246    */
247   vtkSetMacro(UseCurrentAnnotationColor, bool);
248   vtkGetMacro(UseCurrentAnnotationColor, bool);
249   vtkBooleanMacro(UseCurrentAnnotationColor, bool);
250   //@}
251 
252   /**
253    * Retrieve the modified time for this filter.
254    */
255   vtkMTimeType GetMTime() override;
256 
257 protected:
258   vtkApplyColors();
259   ~vtkApplyColors() override;
260 
261   /**
262    * Convert the vtkGraph into vtkPolyData.
263    */
264   int RequestData(
265     vtkInformation *, vtkInformationVector **, vtkInformationVector *) override;
266 
267   /**
268    * Set the input type of the algorithm to vtkGraph.
269    */
270   int FillInputPortInformation(int port, vtkInformation* info) override;
271 
272   void ProcessColorArray(
273     vtkUnsignedCharArray* colorArr,
274     vtkScalarsToColors* lut,
275     vtkAbstractArray* arr,
276     unsigned char color[4],
277     bool scale);
278 
279   vtkScalarsToColors* PointLookupTable;
280   vtkScalarsToColors* CellLookupTable;
281   double DefaultPointColor[3];
282   double DefaultPointOpacity;
283   double DefaultCellColor[3];
284   double DefaultCellOpacity;
285   double SelectedPointColor[3];
286   double SelectedPointOpacity;
287   double SelectedCellColor[3];
288   double SelectedCellOpacity;
289   bool ScalePointLookupTable;
290   bool ScaleCellLookupTable;
291   bool UsePointLookupTable;
292   bool UseCellLookupTable;
293   char* PointColorOutputArrayName;
294   char* CellColorOutputArrayName;
295   bool UseCurrentAnnotationColor;
296 
297 private:
298   vtkApplyColors(const vtkApplyColors&) = delete;
299   void operator=(const vtkApplyColors&) = delete;
300 };
301 
302 #endif
303