1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkScalarsToColors.h,v $
6 Date: $Date: 2003/01/06 20:36:14 $
7 Version: $Revision: 1.28 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 // .NAME vtkScalarsToColors - map scalar values into colors
19 // .SECTION Description
20 // vtkScalarsToColors is a general purpose superclass for objects that
21 // convert scalars to colors. This include vtkLookupTable classes and
22 // color transfer functions.
24 // The scalars to color mapping can be augmented with an additional
25 // uniform alpha blend. This is used, for example, to blend a vtkActor's
26 // opacity with the lookup table values.
29 // vtkLookupTable vtkColorTransferFunction
31 #ifndef __vtkScalarsToColors_h
32 #define __vtkScalarsToColors_h
34 #include "vtkObject.h"
37 class vtkUnsignedCharArray;
39 class VTK_COMMON_EXPORT vtkScalarsToColors : public vtkObject
42 vtkTypeRevisionMacro(vtkScalarsToColors,vtkObject);
43 void PrintSelf(ostream& os, vtkIndent indent);
46 // Perform any processing required (if any) before processing
48 virtual void Build() {};
51 // Sets/Gets the range of scalars which will be mapped.
52 virtual float *GetRange() = 0;
53 virtual void SetRange(float min, float max) = 0;
54 void SetRange(float rng[2])
55 {this->SetRange(rng[0],rng[1]);}
58 // Map one value through the lookup table and return a color defined
59 // as a RGBA unsigned char tuple (4 bytes).
60 virtual unsigned char *MapValue(float v) = 0;
63 // Map one value through the lookup table and return the color as
64 // an RGB array of floats between 0 and 1.
65 virtual void GetColor(float v, float rgb[3]) = 0;
68 // Map one value through the lookup table and return the color as
69 // an RGB array of floats between 0 and 1.
70 float *GetColor(float v)
71 {this->GetColor(v,this->RGB); return this->RGB;}
74 // Map one value through the lookup table and return the alpha value
75 // (the opacity) as a float between 0 and 1.
76 virtual float GetOpacity(float vtkNotUsed(v))
80 // Map one value through the lookup table and return the luminance
81 // 0.3*red + 0.59*green + 0.11*blue as a float between 0 and 1.
82 // Returns the luminance value for the specified scalar value.
83 float GetLuminance(float x)
84 {float rgb[3]; this->GetColor(x,rgb);
85 return static_cast<float>(rgb[0]*0.30 + rgb[1]*0.59 + rgb[2]*0.11);}
88 // Specify an additional opacity (alpha) value to blend with. Values
89 // != 1 modify the resulting color consistent with the requested
90 // form of the output. This is typically used by an actor in order to
92 void SetAlpha(float alpha);
93 vtkGetMacro(Alpha,float);
96 // An internal method maps a data array into a 4-component, unsigned char
97 // RGBA array. The color mode determines the behavior of mapping. If
98 // VTK_COLOR_MODE_DEFAULT is set, then unsigned char data arrays are
99 // treated as colors (and converted to RGBA if necessary); otherwise,
100 // the data is mapped through this instance of ScalarsToColors. The offset
101 // is used for data arrays with more than one component; it indicates
102 // which component to use to do the blending.
103 // When the component argument is -1, then the this object uses its
104 // own selected technique to change a vector into a scalar to map.
105 vtkUnsignedCharArray *MapScalars(vtkDataArray *scalars, int colorMode,
109 // Change mode that maps vectors by magnitude vs. component.
110 vtkSetMacro(VectorMode, int);
111 vtkGetMacro(VectorMode, int);
112 void SetVectorModeToMagnitude();
113 void SetVectorModeToComponent();
116 // If the mapper does not select which component of a vector
117 // to map to colors, you can specify it here.
118 vtkSetMacro(VectorComponent, int);
119 vtkGetMacro(VectorComponent, int);
122 // Map a set of scalars through the lookup table in a single operation.
123 // The output format can be set to VTK_RGBA (4 components),
124 // VTK_RGB (3 components), VTK_LUMINANCE (1 component, greyscale),
125 // or VTK_LUMINANCE_ALPHA (2 components)
126 // If not supplied, the output format defaults to RGBA.
127 void MapScalarsThroughTable(vtkDataArray *scalars,
128 unsigned char *output,
130 void MapScalarsThroughTable(vtkDataArray *scalars,
131 unsigned char *output)
132 {this->MapScalarsThroughTable(scalars,output,VTK_RGBA);}
136 // An internal method typically not used in applications.
137 virtual void MapScalarsThroughTable2(void *input, unsigned char *output,
138 int inputDataType, int numberOfValues,
140 int outputFormat) = 0;
143 // An internal method used to convert a color array to RGBA. The
144 // method instantiates a vtkUnsignedCharArray and returns it. The user is
145 // responsible for managing the memory.
146 virtual vtkUnsignedCharArray *ConvertUnsignedCharToRGBA(
147 vtkUnsignedCharArray *colors, int numComp, int numTuples);
150 vtkScalarsToColors();
151 ~vtkScalarsToColors() {}
155 // How to map arrays with multiple components.
157 // Internal flag used to togle between vector and component mode.
158 // We need this flag because the mapper can override our mode, and
159 // I do not want to change the interface to the map scalars methods.
173 vtkScalarsToColors(const vtkScalarsToColors&); // Not implemented.
174 void operator=(const vtkScalarsToColors&); // Not implemented.