vtkScalarsToColorsPainter.h 8.56 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkScalarsToColorsPainter.h

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
15
// .NAME vtkScalarsToColorsPainter - painter that converts scalars to
16 17
// colors. It enable/disables coloring state depending on the ScalarMode.
// .SECTION Description
18
// This is a painter that converts scalars to
19
// colors. It enable/disables coloring state depending on the ScalarMode.
20
// This painter is composite dataset enabled.
21

22 23
#ifndef vtkScalarsToColorsPainter_h
#define vtkScalarsToColorsPainter_h
24

25
#include "vtkRenderingOpenGLModule.h" // For export macro
26 27
#include "vtkPainter.h"
#include "vtkSmartPointer.h" // needed for vtkSmartPointer.
28 29 30 31 32 33
class vtkDataArray;
class vtkImageData;
class vtkInformationDoubleVectorKey;
class vtkInformationIntegerKey;
class vtkInformationObjectBaseKey;
class vtkInformationStringKey;
34
class vtkDataSet;
35 36
class vtkScalarsToColors;

37
class VTKRENDERINGOPENGL_EXPORT vtkScalarsToColorsPainter : public vtkPainter
38 39 40
{
public:
  static vtkScalarsToColorsPainter* New();
41
  vtkTypeMacro(vtkScalarsToColorsPainter, vtkPainter);
42
  void PrintSelf(ostream& os, vtkIndent indent);
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

  // Description:
  // Control whether the mapper sets the lookuptable range based on its
  // own ScalarRange, or whether it will use the LookupTable ScalarRange
  // regardless of it's own setting. By default the Mapper is allowed to set
  // the LookupTable range, but users who are sharing LookupTables between
  // mappers/actors will probably wish to force the mapper to use the
  // LookupTable unchanged.
  static vtkInformationIntegerKey* USE_LOOKUP_TABLE_SCALAR_RANGE();

  // Description:
  // Specify range in terms of scalar minimum and maximum (smin,smax). These
  // values are used to map scalars into lookup table. Has no effect when
  // UseLookupTableScalarRange is true.
  static vtkInformationDoubleVectorKey* SCALAR_RANGE();

  // Description:
  // Control how the painter works with scalar point data and cell attribute
  // data. See vtkMapper::ScalarMode for more details.
  static vtkInformationIntegerKey* SCALAR_MODE();

  // Description:
65 66 67 68
  // Control how the scalar data is mapped to colors. By default
  // (ColorModeToDefault), unsigned char scalars are treated as colors,
  // and NOT mapped through the lookup table, while everything else is.
  // Setting ColorModeToMapScalars means that all scalar data will be mapped
69 70
  // through the lookup table.
  static vtkInformationIntegerKey* COLOR_MODE();
71

72 73 74 75 76 77
  // Description:
  // By default, vertex color is used to map colors to a surface.
  // Colors are interpolated after being mapped.
  // This option avoids color interpolation by using a one dimensional
  // texture map for the colors.
  static vtkInformationIntegerKey* INTERPOLATE_SCALARS_BEFORE_MAPPING();
78

79 80 81 82 83
  // Description:
  // Specify a lookup table for the mapper to use.
  static vtkInformationObjectBaseKey* LOOKUP_TABLE();
  void SetLookupTable(vtkScalarsToColors *lut);
  vtkScalarsToColors *GetLookupTable();
84

85 86 87 88
  // Description:
  // Create default lookup table. Generally used to create one when none
  // is available with the scalar data.
  virtual void CreateDefaultLookupTable();
89

90 91 92 93 94 95 96 97
  // Description:
  // Turn on/off flag to control whether scalar data is used to color objects.
  static vtkInformationIntegerKey* SCALAR_VISIBILITY();

  // Description:
  // Controls what data array is used to generate colors.
  static vtkInformationIntegerKey* ARRAY_ACCESS_MODE();
  static vtkInformationIntegerKey* ARRAY_ID();
98
  static vtkInformationStringKey*  ARRAY_NAME();
99
  static vtkInformationIntegerKey* ARRAY_COMPONENT();
100
  static vtkInformationIntegerKey* FIELD_DATA_TUPLE_ID();
101

102
  // Description:
103
  // Set the light-model color mode.
104 105
  static vtkInformationIntegerKey* SCALAR_MATERIAL_MODE();

106 107 108 109 110 111
  // Description:
  // For alpha blending, we sometime premultiply the colors
  // with alpha and change the alpha blending function.
  // This call returns whether we are premultiplying or using
  // the default blending function.
  // Currently this checks if the actor has a texture, if not
112
  // it returns true.
113 114 115 116 117 118 119 120 121 122
  // TODO: It is possible to make this decision
  // dependent on key passed down from a painter upstream
  // that makes a more informed decision for alpha blending
  // depending on extensions available, for example.
  virtual int GetPremultiplyColorsWithAlpha(vtkActor* actor);

  // Description:
  // Subclasses need to override this to return the output of the pipeline.
  virtual vtkDataObject *GetOutput();

123 124 125 126 127 128
  // Description:
  // Return the texture size limit. Subclasses need to override this
  // to return the actual correct texture size limit.  Here it is
  // hardcoded to 1024.
  virtual vtkIdType GetTextureSizeLimit();

129
//BTX
130 131
protected:
  vtkScalarsToColorsPainter();
132 133
  virtual ~vtkScalarsToColorsPainter();

134 135
  // Description:
  // Create a new shallow-copied clone for data with no scalars.
136
  virtual vtkDataObject* NewClone(vtkDataObject* data);
137 138 139 140 141

  // Description:
  // Create texture coordinates for the output assuming a texture for the
  // lookuptable has already been created correctly.
  // this->LookupTable is the lookuptable used.
142 143
  void MapScalarsToTexture(vtkDataSet* output,
    vtkDataArray* scalars, vtkDataSet* input);
144 145 146 147 148 149

  // Description:
  // Called just before RenderInternal(). We build the Color array here.
  virtual void PrepareForRendering(vtkRenderer* renderer, vtkActor* actor);

  // Description:
150 151
  // Generates the colors, if needed.
  // If multiply_with_alpha is set, the colors are multiplied with
152
  // alpha.
153
  virtual void MapScalars(vtkDataSet* output,
154
    double alpha, int multiply_with_alpha,
155
    vtkDataSet* input);
156 157 158 159 160 161 162 163 164

  // Description:
  // Called before RenderInternal() if the Information has been changed
  // since the last time this method was called.
  virtual void ProcessInformation(vtkInformation*);

  // Description:
  // Take part in garbage collection.
  virtual void ReportReferences(vtkGarbageCollector *collector);
165

166
  // Description:
167 168
  // Returns if we can use texture maps for scalar coloring. Note this doesn't
  // say we "will" use scalar coloring. It says, if we do use scalar coloring,
169 170
  // we will use a 1D texture.
  // When rendering multiblock datasets, if any 2 blocks provide different
171 172
  // lookup tables for the scalars, then also we cannot use textures. This case
  // can be handled if required.
173 174 175 176 177 178 179
  int CanUseTextureMapForColoring(vtkDataObject* input);


  // Description:
  // Should not be called if CanUseTextureMapForColoring() returns 0.
  void UpdateColorTextureMap(double alpha, int multiply_with_alpha);

180
  // Methods to set the ivars. These are purposefully protected.
181
  // The only means of affecting these should be using the vtkInformation
182
  // object.
183 184
  vtkSetMacro(UseLookupTableScalarRange, int);
  vtkSetVector2Macro(ScalarRange, double);
185 186
  vtkSetMacro(ScalarMode, int);
  vtkSetMacro(ColorMode, int);
187 188 189
  vtkSetMacro(InterpolateScalarsBeforeMapping, int);
  vtkSetMacro(ScalarVisibility, int);
  vtkSetMacro(ScalarMaterialMode, int);
190
  vtkSetMacro(ArrayAccessMode, int);
191
  vtkSetMacro(ArrayComponent, int);
192 193
  vtkSetMacro(ArrayId, int);
  vtkSetStringMacro(ArrayName);
194
  vtkSetMacro(FieldDataTupleId, vtkIdType);
195

196
  vtkDataObject* OutputData;
197 198 199 200 201

  int ArrayAccessMode;
  int ArrayComponent;
  int ArrayId;
  char* ArrayName;
202
  vtkIdType FieldDataTupleId;
203

204
  vtkScalarsToColors *LookupTable;
205 206 207 208
  // Lookup table provided via the scalars. This gets preference over the one
  // set on the mapper by the user.
  vtkSmartPointer<vtkScalarsToColors> ScalarsLookupTable;
  vtkSmartPointer<vtkImageData> ColorTextureMap;
209 210 211 212
  int ColorMode;
  int InterpolateScalarsBeforeMapping;
  int ScalarMode;
  int ScalarMaterialMode;
213
  double LastUsedAlpha; // Essential to ensure alpha changes work correctly
214
                        // for composite datasets.
Jeff Baumes's avatar
Jeff Baumes committed
215
  int LastUsedMultiplyWithAlpha;
216 217 218 219 220
  double ScalarRange[2];
  int ScalarVisibility;
  int UseLookupTableScalarRange;

  vtkTimeStamp OutputUpdateTime;
221 222 223 224

  // This is set when MapScalars decides to use vertex colors for atleast on
  // dataset in the current pass.
  int UsingScalarColoring;
225

226 227 228
private:
  vtkScalarsToColorsPainter(const vtkScalarsToColorsPainter&); // Not implemented.
  void operator=(const vtkScalarsToColorsPainter&); // Not implemented.
229
//ETX
230 231 232
};

#endif