VTK
vtkScalarsToColors.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkScalarsToColors.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 =========================================================================*/
48 #ifndef vtkScalarsToColors_h
49 #define vtkScalarsToColors_h
50 
51 #include "vtkCommonCoreModule.h" // For export macro
52 #include "vtkVariant.h" // Set/get annotation methods require variants.
53 #include "vtkObject.h"
54 
55 class vtkAbstractArray;
56 class vtkDataArray;
58 class vtkAbstractArray;
59 class vtkStringArray;
60 
61 
63 {
64 public:
66  void PrintSelf(ostream& os, vtkIndent indent);
67  static vtkScalarsToColors *New();
68 
71  virtual int IsOpaque();
72 
75  virtual void Build() {}
76 
78 
79  virtual double *GetRange();
80  virtual void SetRange(double min, double max);
81  void SetRange(double rng[2])
82  {this->SetRange(rng[0],rng[1]);}
84 
87  virtual unsigned char *MapValue(double v);
88 
91  virtual void GetColor(double v, double rgb[3]);
92 
94 
96  double *GetColor(double v)
97  {this->GetColor(v,this->RGB); return this->RGB;}
99 
103  virtual double GetOpacity(double v);
104 
106 
109  double GetLuminance(double x)
110  {double rgb[3]; this->GetColor(x,rgb);
111  return static_cast<double>(rgb[0]*0.30 + rgb[1]*0.59 + rgb[2]*0.11);}
113 
115 
119  virtual void SetAlpha(double alpha);
120  vtkGetMacro(Alpha,double);
122 
124 
138  virtual vtkUnsignedCharArray *MapScalars(vtkDataArray *scalars, int colorMode,
139  int component);
140  virtual vtkUnsignedCharArray *MapScalars(vtkAbstractArray *scalars, int colorMode,
141  int component);
143 
145 
148  vtkSetMacro(VectorMode, int);
149  vtkGetMacro(VectorMode, int);
150  void SetVectorModeToMagnitude();
151  void SetVectorModeToComponent();
152  void SetVectorModeToRGBColors();
154 
155 //BTX
156  enum VectorModes {
157  MAGNITUDE=0,
158  COMPONENT=1,
159  RGBCOLORS=2
160  };
161 //ETX
162 
163 
165 
167  vtkSetMacro(VectorComponent, int);
168  vtkGetMacro(VectorComponent, int);
170 
172 
177  vtkSetMacro(VectorSize, int);
178  vtkGetMacro(VectorSize, int);
180 
182 
187  void MapVectorsThroughTable(void *input, unsigned char *output,
188  int inputDataType, int numberOfValues,
189  int inputIncrement, int outputFormat,
190  int vectorComponent, int vectorSize);
191  void MapVectorsThroughTable(void *input, unsigned char *output,
192  int inputDataType, int numberOfValues,
193  int inputIncrement, int outputFormat)
194  { this->MapVectorsThroughTable(input, output, inputDataType, numberOfValues,
195  inputIncrement, outputFormat, -1, -1); }
197 
199 
205  void MapScalarsThroughTable(vtkDataArray *scalars,
206  unsigned char *output,
207  int outputFormat);
209  unsigned char *output)
210  {this->MapScalarsThroughTable(scalars,output,VTK_RGBA);}
211  void MapScalarsThroughTable(void *input, unsigned char *output,
212  int inputDataType, int numberOfValues,
213  int inputIncrement,
214  int outputFormat)
215  {this->MapScalarsThroughTable2(input, output, inputDataType,
216  numberOfValues, inputIncrement, outputFormat);}
218 
220 
223  virtual void MapScalarsThroughTable2(void *input, unsigned char *output,
224  int inputDataType, int numberOfValues,
225  int inputIncrement,
226  int outputFormat);
228 
230  virtual void DeepCopy(vtkScalarsToColors *o);
231 
233 
235  virtual int UsingLogScale()
236  { return 0; }
238 
240  virtual vtkIdType GetNumberOfAvailableColors();
241 
243 
252  virtual void SetAnnotations( vtkAbstractArray* values, vtkStringArray* annotations );
253  vtkGetObjectMacro(AnnotatedValues,vtkAbstractArray);
254  vtkGetObjectMacro(Annotations,vtkStringArray);
256 
260  virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation);
261 
264  virtual vtkIdType SetAnnotation(vtkStdString value, vtkStdString annotation);
265 
268  vtkIdType GetNumberOfAnnotatedValues();
269 
272  vtkVariant GetAnnotatedValue(vtkIdType idx);
273 
276  vtkStdString GetAnnotation(vtkIdType idx);
277 
280  virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]);
281 
284  vtkIdType GetAnnotatedValueIndex( vtkVariant val );
285 
288  vtkIdType GetAnnotatedValueIndexInternal(vtkVariant& val);
289 
300  virtual void GetIndexedColor(vtkIdType i, double rgba[4]);
301 
305  virtual bool RemoveAnnotation(vtkVariant value);
306 
308  virtual void ResetAnnotations();
309 
311 
316  vtkSetMacro(IndexedLookup,int);
317  vtkGetMacro(IndexedLookup,int);
318  vtkBooleanMacro(IndexedLookup,int);
320 
321 
323 
326  template<typename T> static
327  unsigned char ColorToUChar(T t)
328  {
329  return t;
330  }
331  template<typename T> static
332  void ColorToUChar(T t, unsigned char* dest)
333  {
334  *dest = ColorToUChar(t);
335  }
337 
338 
339 
340 protected:
343 
345 
354  void MapColorsToColors(void *input, unsigned char *output,
355  int inputDataType, int numberOfValues,
356  int numberOfComponents, int vectorSize,
357  int outputFormat);
359 
361 
364  vtkUnsignedCharArray *ConvertToRGBA(
365  vtkDataArray *colors, int numComp, int numTuples);
367 
368 
370 
372  void MapVectorsToMagnitude(void *input, double *output,
373  int inputDataType, int numberOfValues,
374  int numberOfComponents, int vectorSize);
376 
379  virtual vtkIdType CheckForAnnotatedValue( vtkVariant value );
380 
383  virtual void UpdateAnnotatedValueMap();
384 
385  // Annotations of specific values.
388 
389  class vtkInternalAnnotatedValueMap;
390  vtkInternalAnnotatedValueMap* AnnotatedValueMap;
391 
393 
394  double Alpha;
395 
396  // How to map arrays with multiple components.
400 
401  // Obsolete, kept so subclasses will still compile
403 
404  unsigned char RGBABytes[4];
405 
406 private:
407  double RGB[3];
408  double InputRange[2];
409 
410  vtkScalarsToColors(const vtkScalarsToColors&); // Not implemented.
411  void operator=(const vtkScalarsToColors&); // Not implemented.
412 };
413 
415 
418 template<> inline
419 unsigned char vtkScalarsToColors::ColorToUChar(double t)
420 {
421  return static_cast<unsigned char>(t*255 + 0.5);
422 }
423 template<> inline
424 unsigned char vtkScalarsToColors::ColorToUChar(float t)
425 {
426  return static_cast<unsigned char>(t*255 + 0.5);
427 }
429 
430 
431 #endif
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output)
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
static void ColorToUChar(T t, unsigned char *dest)
abstract base class for most VTK objects
Definition: vtkObject.h:61
Abstract superclass for all arrays.
void SetRange(double rng[2])
#define VTKCOMMONCORE_EXPORT
void DeepCopy(vtkPistonReference *self, vtkPistonReference *other)
a vtkAbstractArray subclass for strings
int vtkIdType
Definition: vtkType.h:275
A atomic type representing the union of many types.
Definition: vtkVariant.h:78
Superclass for mapping scalar values to colors.
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
static unsigned char ColorToUChar(T t)
void MapScalarsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
dynamic, self-adjusting array of unsigned char
#define VTK_RGBA
double * GetColor(double v)
vtkStringArray * Annotations
void MapVectorsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
virtual void Build()
static vtkObject * New()
vtkInternalAnnotatedValueMap * AnnotatedValueMap
vtkAbstractArray * AnnotatedValues
#define max(a, b)
double GetLuminance(double x)
virtual int UsingLogScale()