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