OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I686LINUX / util / I686LINUX / include / vtk / vtkScalarsToColors.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkScalarsToColors.h,v $
5   Language:  C++
6   Date:      $Date: 2003/01/06 20:36:14 $
7   Version:   $Revision: 1.28 $
8
9   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
10   All rights reserved.
11   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
12
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.
16
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.
23 //
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.
27 //
28 // .SECTION See Also
29 // vtkLookupTable vtkColorTransferFunction
30
31 #ifndef __vtkScalarsToColors_h
32 #define __vtkScalarsToColors_h
33
34 #include "vtkObject.h"
35
36 class vtkDataArray;
37 class vtkUnsignedCharArray;
38
39 class VTK_COMMON_EXPORT vtkScalarsToColors : public vtkObject
40 {
41 public:
42   vtkTypeRevisionMacro(vtkScalarsToColors,vtkObject);
43   void PrintSelf(ostream& os, vtkIndent indent);
44   
45   // Description:
46   // Perform any processing required (if any) before processing 
47   // scalars.
48   virtual void Build() {};
49   
50   // Description:
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]);}
56   
57   // Description:
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;
61
62   // Description:
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;
66
67   // Description:
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;}
72
73   // Description:
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)) 
77     {return 1.0;}
78
79   // Description:
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);}
86
87   // Description:
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
91   // blend its opacity.
92   void SetAlpha(float alpha);
93   vtkGetMacro(Alpha,float);
94
95   // Description:
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,
106                                    int component);
107
108   // Description:
109   // Change mode that maps vectors by magnitude vs. component.
110   vtkSetMacro(VectorMode, int);
111   vtkGetMacro(VectorMode, int);
112   void SetVectorModeToMagnitude();
113   void SetVectorModeToComponent();
114
115   // Description:
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);
120   
121   // Description:
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,
129                               int outputFormat);
130   void MapScalarsThroughTable(vtkDataArray *scalars, 
131                               unsigned char *output) 
132     {this->MapScalarsThroughTable(scalars,output,VTK_RGBA);}
133
134
135   // Description:
136   // An internal method typically not used in applications.
137   virtual void MapScalarsThroughTable2(void *input, unsigned char *output,
138                                        int inputDataType, int numberOfValues,
139                                        int inputIncrement, 
140                                        int outputFormat) = 0;
141
142   // Description:
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);
148
149 protected:
150   vtkScalarsToColors();
151   ~vtkScalarsToColors() {}
152
153   float Alpha;
154
155   // How to map arrays with multiple components.
156   int VectorMode;
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.
160   int UseMagnitude;
161   int VectorComponent;
162
163 //BTX
164   enum VectorModes {
165     MAGNITUDE=0,
166     COMPONENT=1
167   };
168 //ETX
169
170 private:
171   float RGB[3];
172 private:
173   vtkScalarsToColors(const vtkScalarsToColors&);  // Not implemented.
174   void operator=(const vtkScalarsToColors&);  // Not implemented.
175 };
176
177 #endif
178
179
180