vtkScalarBarActor.h 6.47 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkScalarBarActor.h

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
Will Schroeder's avatar
Will Schroeder committed
9

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
13 14 15 16 17

=========================================================================*/
// .NAME vtkScalarBarActor - Create a scalar bar with labels
// .SECTION Description
// vtkScalarBarActor creates a scalar bar with annotation text. A scalar
Bill Lorensen's avatar
Bill Lorensen committed
18
// bar is a legend that indicates to the viewer the correspondence between
19 20 21 22 23
// color value and data value. The legend consists of a rectangular bar 
// made of rectangular pieces each colored a constant value. Since 
// vtkScalarBarActor is a subclass of vtkActor2D, it is drawn in the image 
// plane (i.e., in the renderer's viewport) on top of the 3D graphics window.
//
Ken Martin's avatar
Ken Martin committed
24
// To use vtkScalarBarActor you must associate a vtkScalarsToColors (or
25 26 27 28 29 30
// subclass) with it. The lookup table defines the colors and the
// range of scalar values used to map scalar data.  Typically, the
// number of colors shown in the scalar bar is not equal to the number
// of colors in the lookup table, in which case sampling of
// the lookup table is performed. 
//
Bill Lorensen's avatar
Bill Lorensen committed
31
// Other optional capabilities include specifying the fraction of the
32
// viewport size (both x and y directions) which will control the size
33 34
// of the scalar bar and the number of annotation labels. The actual position
// of the scalar bar on the screen is controlled by using the
35 36 37 38 39
// vtkActor2D::SetPosition() method (by default the scalar bar is
// centered in the viewport).  Other features include the ability to
// orient the scalar bar horizontally of vertically and controlling
// the format (printf style) with which to print the labels on the
// scalar bar. Also, the vtkScalarBarActor's property is applied to
40
// the scalar bar and annotation (including layer, and
41
// compositing operator).
42 43 44 45
//
// Set the text property/attributes of the title and the labels through the 
// vtkTextProperty objects associated to this actor.
//
46 47 48 49
// .SECTION Caveats
// If a vtkLogLookupTable is specified as the lookup table to use, then the
// labels are created using a logarithmic scale.
//
50
// .SECTION See Also
51
// vtkActor2D vtkTextProperty vtkTextMapper vtkPolyDataMapper2D
52 53 54 55 56

#ifndef __vtkScalarBarActor_h
#define __vtkScalarBarActor_h

#include "vtkActor2D.h"
57 58 59 60 61

class vtkPolyData;
class vtkPolyDataMapper2D;
class vtkScalarsToColors;
class vtkTextMapper;
62
class vtkTextProperty;
63 64 65 66

#define VTK_ORIENT_HORIZONTAL 0
#define VTK_ORIENT_VERTICAL 1

67
class VTK_RENDERING_EXPORT vtkScalarBarActor : public vtkActor2D
68 69
{
public:
Brad King's avatar
Brad King committed
70
  vtkTypeRevisionMacro(vtkScalarBarActor,vtkActor2D);
71
  void PrintSelf(ostream& os, vtkIndent indent);
72

73
  // Description:
74
  // Instantiate object with 64 maximum colors; 5 labels; %%-#6.3g label
75 76
  // format, no title, and vertical orientation. The initial scalar bar
  // size is (0.05 x 0.8) of the viewport size.
77
  static vtkScalarBarActor *New();
78

79 80
  // Description:
  // Draw the scalar bar and annotation text to the screen.
81
  int RenderOpaqueGeometry(vtkViewport* viewport);
82
  int RenderTranslucentGeometry(vtkViewport*) { return 0; };
83
  int RenderOverlay(vtkViewport* viewport);
84

85 86 87 88 89 90
  // Description:
  // Release any graphics resources that are being consumed by this actor.
  // The parameter window could be used to determine which graphic
  // resources to release.
  virtual void ReleaseGraphicsResources(vtkWindow *);

91
  // Description:
92 93 94
  // Set/Get the vtkLookupTable to use. The lookup table specifies the number
  // of colors to use in the table (if not overridden), as well as the scalar
  // range.
95
  virtual void SetLookupTable(vtkScalarsToColors*);
Ken Martin's avatar
Ken Martin committed
96
  vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
97 98

  // Description:
Bill Lorensen's avatar
Bill Lorensen committed
99
  // Set/Get the maximum number of scalar bar segments to show. This may
100 101 102 103 104 105 106 107 108 109 110 111
  // differ from the number of colors in the lookup table, in which case
  // the colors are samples from the lookup table.
  vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_LARGE_INTEGER);
  vtkGetMacro(MaximumNumberOfColors, int);
  
  // Description:
  // Set/Get the number of annotation labels to show.
  vtkSetClampMacro(NumberOfLabels, int, 0, 64);
  vtkGetMacro(NumberOfLabels, int);
  
  // Description:
  // Control the orientation of the scalar bar.
Jim Miller's avatar
Style  
Jim Miller committed
112
  vtkSetClampMacro(Orientation,int,VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
113
  vtkGetMacro(Orientation, int);
Jim Miller's avatar
Style  
Jim Miller committed
114 115 116
  void SetOrientationToHorizontal()
       {this->SetOrientation(VTK_ORIENT_HORIZONTAL);};
  void SetOrientationToVertical() {this->SetOrientation(VTK_ORIENT_VERTICAL);};
117 118

  // Description:
119 120 121 122 123 124 125 126 127
  // Set/Get the title text property.
  virtual void SetTitleTextProperty(vtkTextProperty *p);
  vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
  
  // Description:
  // Set/Get the labels text property.
  virtual void SetLabelTextProperty(vtkTextProperty *p);
  vtkGetObjectMacro(LabelTextProperty,vtkTextProperty);
    
128 129 130
  // Description:
  // Set/Get the format with which to print the labels on the scalar
  // bar.
Ken Martin's avatar
Ken Martin committed
131
  vtkSetStringMacro(LabelFormat);
132 133 134 135
  vtkGetStringMacro(LabelFormat);

  // Description:
  // Set/Get the title of the scalar bar actor,
Ken Martin's avatar
Ken Martin committed
136
  vtkSetStringMacro(Title);
137 138
  vtkGetStringMacro(Title);

Ken Martin's avatar
Ken Martin committed
139
  // Description:
Will Schroeder's avatar
Will Schroeder committed
140 141
  // Shallow copy of a scalar bar actor. Overloads the virtual vtkProp method.
  void ShallowCopy(vtkProp *prop);
Ken Martin's avatar
Ken Martin committed
142

143
protected:
144 145 146
  vtkScalarBarActor();
  ~vtkScalarBarActor();

Ken Martin's avatar
Ken Martin committed
147
  vtkScalarsToColors *LookupTable;
148 149 150
  vtkTextProperty *TitleTextProperty;
  vtkTextProperty *LabelTextProperty;

151 152
  int   MaximumNumberOfColors;
  int   NumberOfLabels;
153
  int   NumberOfLabelsBuilt;
154 155 156
  int   Orientation;
  char  *Title;
  char  *LabelFormat;
157

158 159
  vtkTextMapper **TextMappers;
  virtual void AllocateAndSizeLabels(int *labelSize, int *size,
Ken Martin's avatar
Ken Martin committed
160
                                     vtkViewport *viewport, double *range);
161

162 163 164 165 166 167 168 169 170 171 172
private:
  vtkTextMapper *TitleMapper;
  vtkActor2D    *TitleActor;

  vtkActor2D    **TextActors;

  vtkPolyData         *ScalarBar;
  vtkPolyDataMapper2D *ScalarBarMapper;
  vtkActor2D          *ScalarBarActor;

  vtkTimeStamp  BuildTime;
173 174
  int LastSize[2];
  int LastOrigin[2];
Ken Martin's avatar
Ken Martin committed
175

Ken Martin's avatar
Ken Martin committed
176
  void SizeTitle(int *titleSize, int *size, vtkViewport *viewport);
177

178 179 180
private:
  vtkScalarBarActor(const vtkScalarBarActor&);  // Not implemented.
  void operator=(const vtkScalarBarActor&);  // Not implemented.
181 182 183 184 185
};


#endif