VTK  9.1.0
vtkScalarBarActor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkScalarBarActor.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 =========================================================================*/
56 #ifndef vtkScalarBarActor_h
57 #define vtkScalarBarActor_h
58 
59 #include "vtkActor2D.h"
60 #include "vtkDoubleArray.h" // for ivars
61 #include "vtkRenderingAnnotationModule.h" // For export macro
62 
63 class vtkColor3ub;
64 class vtkPolyData;
66 class vtkProperty2D;
67 class vtkScalarsToColors;
69 class vtkTextActor;
70 class vtkTextMapper;
71 class vtkTextProperty;
72 class vtkTexture;
73 class vtkTexturedActor2D;
74 
75 #define VTK_ORIENT_HORIZONTAL 0
76 #define VTK_ORIENT_VERTICAL 1
77 
78 class VTKRENDERINGANNOTATION_EXPORT vtkScalarBarActor : public vtkActor2D
79 {
80 public:
81  vtkTypeMacro(vtkScalarBarActor, vtkActor2D);
82  void PrintSelf(ostream& os, vtkIndent indent) override;
83 
90 
92 
95  int RenderOpaqueGeometry(vtkViewport* viewport) override;
96  int RenderTranslucentPolygonalGeometry(vtkViewport*) override { return 0; }
97  int RenderOverlay(vtkViewport* viewport) override;
99 
104 
111 
117  virtual void GetScalarBarRect(int rect[4], vtkViewport* viewport);
118 
120 
127  vtkGetObjectMacro(LookupTable, vtkScalarsToColors);
129 
131 
138  vtkSetMacro(UseOpacity, vtkTypeBool);
139  vtkGetMacro(UseOpacity, vtkTypeBool);
140  vtkBooleanMacro(UseOpacity, vtkTypeBool);
142 
144 
149  vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_INT_MAX);
150  vtkGetMacro(MaximumNumberOfColors, int);
152 
154 
157  vtkSetClampMacro(NumberOfLabels, int, 0, 64);
158  vtkGetMacro(NumberOfLabels, int);
160 
162 
165  virtual void SetCustomLabels(vtkDoubleArray* labels);
166  vtkGetObjectMacro(CustomLabels, vtkDoubleArray);
168 
170 
174  vtkGetMacro(UseCustomLabels, bool);
175  vtkSetMacro(UseCustomLabels, bool);
176  vtkBooleanMacro(UseCustomLabels, bool);
178 
180 
183  vtkSetClampMacro(Orientation, int, VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
184  vtkGetMacro(Orientation, int);
185  void SetOrientationToHorizontal() { this->SetOrientation(VTK_ORIENT_HORIZONTAL); }
186  void SetOrientationToVertical() { this->SetOrientation(VTK_ORIENT_VERTICAL); }
188 
190 
194  vtkGetObjectMacro(TitleTextProperty, vtkTextProperty);
196 
198 
202  vtkGetObjectMacro(LabelTextProperty, vtkTextProperty);
204 
206 
210  vtkGetObjectMacro(AnnotationTextProperty, vtkTextProperty);
212 
214 
218  vtkSetStringMacro(LabelFormat);
219  vtkGetStringMacro(LabelFormat);
221 
223 
226  vtkSetStringMacro(Title);
227  vtkGetStringMacro(Title);
229 
231 
234  vtkSetStringMacro(ComponentTitle);
235  vtkGetStringMacro(ComponentTitle);
237 
241  void ShallowCopy(vtkProp* prop) override;
242 
244 
247  vtkSetMacro(TextureGridWidth, double);
248  vtkGetMacro(TextureGridWidth, double);
250 
252 
255  vtkGetObjectMacro(TextureActor, vtkTexturedActor2D);
257 
258  enum
259  {
260  PrecedeScalarBar = 0,
261  SucceedScalarBar
262  };
263 
265 
273  vtkSetClampMacro(TextPosition, int, PrecedeScalarBar, SucceedScalarBar);
274  vtkGetMacro(TextPosition, int);
276  {
277  this->SetTextPosition(vtkScalarBarActor::PrecedeScalarBar);
278  }
280  {
281  this->SetTextPosition(vtkScalarBarActor::SucceedScalarBar);
282  }
284 
286 
293  vtkSetMacro(MaximumWidthInPixels, int);
294  vtkGetMacro(MaximumWidthInPixels, int);
295  vtkSetMacro(MaximumHeightInPixels, int);
296  vtkGetMacro(MaximumHeightInPixels, int);
298 
300 
305  vtkSetMacro(AnnotationLeaderPadding, double);
306  vtkGetMacro(AnnotationLeaderPadding, double);
308 
310 
315  vtkSetMacro(DrawAnnotations, vtkTypeBool);
316  vtkGetMacro(DrawAnnotations, vtkTypeBool);
317  vtkBooleanMacro(DrawAnnotations, vtkTypeBool);
319 
321 
326  vtkSetMacro(DrawNanAnnotation, vtkTypeBool);
327  vtkGetMacro(DrawNanAnnotation, vtkTypeBool);
328  vtkBooleanMacro(DrawNanAnnotation, vtkTypeBool);
330 
332 
337  vtkSetMacro(DrawBelowRangeSwatch, bool);
338  vtkGetMacro(DrawBelowRangeSwatch, bool);
339  vtkBooleanMacro(DrawBelowRangeSwatch, bool);
341 
343 
346  vtkSetStringMacro(BelowRangeAnnotation);
347  vtkGetStringMacro(BelowRangeAnnotation);
349 
351 
356  vtkSetMacro(DrawAboveRangeSwatch, bool);
357  vtkGetMacro(DrawAboveRangeSwatch, bool);
358  vtkBooleanMacro(DrawAboveRangeSwatch, bool);
360 
362 
365  vtkSetStringMacro(AboveRangeAnnotation);
366  vtkGetStringMacro(AboveRangeAnnotation);
369 
377  vtkSetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
378  vtkGetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
379  vtkBooleanMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
381 
383 
386  vtkSetStringMacro(NanAnnotation);
387  vtkGetStringMacro(NanAnnotation);
389 
391 
399  vtkSetMacro(AnnotationTextScaling, vtkTypeBool);
400  vtkGetMacro(AnnotationTextScaling, vtkTypeBool);
401  vtkBooleanMacro(AnnotationTextScaling, vtkTypeBool);
403 
405 
409  vtkSetMacro(DrawBackground, vtkTypeBool);
410  vtkGetMacro(DrawBackground, vtkTypeBool);
411  vtkBooleanMacro(DrawBackground, vtkTypeBool);
413 
415 
419  vtkSetMacro(DrawFrame, vtkTypeBool);
420  vtkGetMacro(DrawFrame, vtkTypeBool);
421  vtkBooleanMacro(DrawFrame, vtkTypeBool);
423 
425 
429  vtkSetMacro(DrawColorBar, vtkTypeBool);
430  vtkGetMacro(DrawColorBar, vtkTypeBool);
431  vtkBooleanMacro(DrawColorBar, vtkTypeBool);
433 
435 
438  vtkSetMacro(DrawTickLabels, vtkTypeBool);
439  vtkGetMacro(DrawTickLabels, vtkTypeBool);
440  vtkBooleanMacro(DrawTickLabels, vtkTypeBool);
442 
444 
448  vtkGetObjectMacro(BackgroundProperty, vtkProperty2D);
450 
452 
455  virtual void SetFrameProperty(vtkProperty2D* p);
456  vtkGetObjectMacro(FrameProperty, vtkProperty2D);
458 
460 
464  vtkGetMacro(TextPad, int);
465  vtkSetMacro(TextPad, int);
467 
469 
474  vtkGetMacro(VerticalTitleSeparation, int);
475  vtkSetMacro(VerticalTitleSeparation, int);
477 
479 
483  vtkGetMacro(BarRatio, double);
484  vtkSetClampMacro(BarRatio, double, 0., 1.);
486 
488 
494  vtkGetMacro(TitleRatio, double);
495  vtkSetClampMacro(TitleRatio, double, 0., 1.);
497 
499 
505  vtkSetMacro(UnconstrainedFontSize, bool);
506  vtkGetMacro(UnconstrainedFontSize, bool);
507  vtkBooleanMacro(UnconstrainedFontSize, bool);
509 
510 protected:
512  ~vtkScalarBarActor() override;
513 
538  virtual void RebuildLayout(vtkViewport* viewport);
539 
545  virtual int RebuildLayoutIfNeeded(vtkViewport* viewport);
546 
550  virtual void FreeLayoutStorage();
551 
560  virtual void ComputeFrame();
561 
572 
576  virtual void ComputeSwatchPad();
577 
578  // This method must set this->P->NanSwatchSize and this->P->NanBox.
579  // It may depend on layout performed by ComputeScalarBarThickness.
580  virtual void LayoutNanSwatch();
581 
588  virtual void LayoutBelowRangeSwatch();
589 
596  virtual void LayoutAboveRangeSwatch();
597 
605 
609  virtual void PrepareTitleText();
610 
621  virtual void LayoutTitle();
622 
628 
637  virtual void ComputeScalarBarLength();
638 
650  virtual void LayoutTicks();
651 
659  virtual void LayoutAnnotations();
660 
664  virtual void ConfigureAnnotations();
665 
669  virtual void ConfigureFrame();
670 
674  virtual void DrawBoxes();
675 
679  virtual void ConfigureScalarBar();
680 
684  virtual void ConfigureTitle();
685 
689  virtual void ConfigureTicks();
690 
697  virtual void ConfigureNanSwatch();
698 
703  virtual void ConfigureAboveBelowRangeSwatch(bool above);
704 
713  virtual void EditAnnotations() {}
714 
720  virtual void SizeTitle(double* titleSize, int* size, vtkViewport* viewport);
721 
726  vtkScalarsToColors* lkup, double start, double delta, const double* range);
727 
732  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
738  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
739 
746  vtkDoubleArray* CustomLabels = nullptr;
747  bool UseCustomLabels = false;
748  vtkTypeBool DrawBackground; // off by default
749  vtkTypeBool DrawFrame; // off by default
750  vtkTypeBool DrawColorBar; // on by default
751  vtkTypeBool DrawTickLabels; // on by default
758  char* Title;
760  char* LabelFormat;
761  vtkTypeBool UseOpacity; // off by default
770  int TextPad;
772  double BarRatio;
773  double TitleRatio;
774  bool UnconstrainedFontSize; // off by default
775 
779 
783  int LastSize[2];
784  int LastOrigin[2];
785 
787 
789 
794 
801 
805 
810 
811 private:
812  vtkScalarBarActor(const vtkScalarBarActor&) = delete;
813  void operator=(const vtkScalarBarActor&) = delete;
814 };
815 
816 #endif
a actor that draws 2D data
Definition: vtkActor2D.h:40
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:195
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition: vtkIndent.h:34
draw vtkPolyData onto the image plane
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:86
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:57
represent surface properties of a 2D image
Definition: vtkProperty2D.h:38
Internal state for the scalar bar actor shared with subclasses.
Create a scalar bar with labels.
virtual void LayoutNanSwatch()
vtkPolyData * Background
Polygon used to fill the background.
vtkTypeBool DrawFrame
User-changeable settings.
int RenderOverlay(vtkViewport *viewport) override
Draw the scalar bar and annotation text to the screen.
virtual void ComputeScalarBarThickness()
Determine how thick the scalar bar should be (on an axis perpendicular to the direction in which scal...
vtkTypeBool AnnotationTextScaling
User-changeable settings.
virtual void SetAnnotationTextProperty(vtkTextProperty *p)
Set/Get the annotation text property.
virtual void FreeLayoutStorage()
Free internal storage used by the previous layout.
virtual void ConfigureAnnotations()
Generate/configure the annotation labels using the laid-out geometry.
static vtkScalarBarActor * New()
Instantiate object with 64 maximum colors; 5 labels; %%-#6.3g label format, no title,...
char * LabelFormat
User-changeable settings.
virtual void ComputeFrame()
If the scalar bar should be inset into a frame or rendered with a solid background,...
vtkTypeBool DrawBackground
User-changeable settings.
virtual void ComputeSwatchPad()
Compute a correct SwatchPad.
int RenderOpaqueGeometry(vtkViewport *viewport) override
Draw the scalar bar and annotation text to the screen.
vtkTextActor * TitleActor
The legend title text renderer.
~vtkScalarBarActor() override
int Orientation
User-changeable settings.
virtual void LayoutTitle()
Determine the position and size of the scalar bar title box.
char * BelowRangeAnnotation
User-changeable settings.
vtkProperty2D * BackgroundProperty
User-changeable settings.
virtual void ConfigureNanSwatch()
Generate/configure the NaN swatch using the laid-out geometry.
void SetOrientationToVertical()
Control the orientation of the scalar bar.
vtkTypeBool HasTranslucentPolygonalGeometry() override
Does this prop have some translucent polygonal geometry?
int MaximumNumberOfColors
User-changeable settings.
vtkTextProperty * AnnotationTextProperty
Font for annotation labels.
vtkTexturedActor2D * TextureActor
Actor for TexturePolyData.
virtual void LayoutBelowRangeSwatch()
Determine the size of the Below Range if it is to be rendered.
int NumberOfLabels
User-changeable settings.
double BarRatio
User-changeable settings.
void SetOrientationToHorizontal()
Control the orientation of the scalar bar.
vtkPolyData * Frame
Polyline used to highlight frame.
int PlaceAnnotationsVertically(double barX, double barY, double barWidth, double barHeight, double delta, double pad)
This method is called by ConfigureAnnotationLabels when Orientation is VTK_ORIENT_VERTICAL.
vtkPolyData * ScalarBar
Polygon(s) colored by LookupTable.
virtual void ConfigureTicks()
Generate/configure the tick-mark actors using the laid-out geometry.
vtkPolyDataMapper2D * FrameMapper
Mapper for Frame.
virtual void LayoutAnnotations()
This method must lay out annotation text and leader lines so they do not overlap.
virtual void RebuildLayout(vtkViewport *viewport)
Called from within RenderOpaqueGeometry when the internal state members need to be updated before ren...
int MapAnnotationLabels(vtkScalarsToColors *lkup, double start, double delta, const double *range)
Allocate actors for lookup table annotations and position them properly.
int TextPosition
User-changeable settings.
int MaximumHeightInPixels
User-changeable settings.
int VerticalTitleSeparation
User-changeable settings.
double AnnotationLeaderPadding
User-changeable settings.
bool UnconstrainedFontSize
User-changeable settings.
vtkTextProperty * TitleTextProperty
Font for the legend title.
virtual int RebuildLayoutIfNeeded(vtkViewport *viewport)
Calls RebuildLayout if it is needed such as when positions etc have changed.
int TextPad
User-changeable settings.
vtkActor2D * FrameActor
Actor for Frame.
vtkProperty2D * FrameProperty
User-changeable settings.
vtkPolyData * TexturePolyData
Polygon colored when UseOpacity is true.
int RenderTranslucentPolygonalGeometry(vtkViewport *) override
Draw the scalar bar and annotation text to the screen.
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this actor.
virtual void SetTextPositionToPrecedeScalarBar()
Should the title and tick marks precede the scalar bar or succeed it? This is measured along the view...
virtual void SetTextPositionToSucceedScalarBar()
Should the title and tick marks precede the scalar bar or succeed it? This is measured along the view...
char * Title
User-changeable settings.
vtkTypeBool UseOpacity
User-changeable settings.
bool DrawBelowRangeSwatch
User-changeable settings.
virtual void LayoutAboveRangeSwatchPosn()
Determine the position of the Above Range if it is to be rendered.
virtual void EditAnnotations()
Subclasses may override this method to alter this->P->Labels, allowing the addition and removal of an...
vtkActor2D * BackgroundActor
Actor for Background.
virtual void DrawBoxes()
For debugging, add placement boxes to the frame polydata.
virtual void SetLookupTable(vtkScalarsToColors *)
Set/Get the lookup table to use.
char * AboveRangeAnnotation
User-changeable settings.
vtkTextProperty * LabelTextProperty
Font for tick labels.
vtkTypeBool DrawTickLabels
User-changeable settings.
virtual void ConfigureFrame()
Generate/configure the representation of the frame from laid-out geometry.
virtual void SetCustomLabels(vtkDoubleArray *labels)
Set/Get the fixed locations to use.
vtkTypeBool FixedAnnotationLeaderLineColor
User-changeable settings.
vtkTypeBool DrawColorBar
User-changeable settings.
char * NanAnnotation
User-changeable settings.
vtkPolyDataMapper2D * BackgroundMapper
Mapper for Background.
virtual void SetTitleTextProperty(vtkTextProperty *p)
Set/Get the title text property.
virtual void GetScalarBarRect(int rect[4], vtkViewport *viewport)
Fills rect with the dimensions of the scalar bar in viewport coordinates.
virtual void SizeTitle(double *titleSize, int *size, vtkViewport *viewport)
Compute the best size for the legend title.
virtual void ConfigureAboveBelowRangeSwatch(bool above)
Generate/configure the above/below range swatch using the laid-out geometry.
int PlaceAnnotationsHorizontally(double barX, double barY, double barWidth, double barHeight, double delta, double pad)
This method is called by ConfigureAnnotationLabels when Orientation is VTK_ORIENT_HORIZONTAL.
vtkTypeBool DrawNanAnnotation
User-changeable settings.
virtual void ConfigureScalarBar()
Generate/configure the scalar bar representation from laid-out geometry.
virtual void ComputeScalarBarLength()
Determine how long the scalar bar should be (on an axis parallel to the direction in which scalar val...
virtual void ConfigureTitle()
Generate/configure the title actor using the laid-out geometry.
void ShallowCopy(vtkProp *prop) override
Shallow copy of a scalar bar actor.
char * ComponentTitle
User-changeable settings.
vtkPolyDataMapper2D * ScalarBarMapper
Mapper for ScalarBar.
vtkTexture * Texture
Color data for TexturePolyData.
vtkTypeBool DrawAnnotations
User-changeable settings.
vtkScalarBarActorInternal * P
Containers shared with subclasses.
vtkActor2D * ScalarBarActor
Actor for ScalarBar.
virtual void SetBackgroundProperty(vtkProperty2D *p)
Set/Get the background property.
double TitleRatio
User-changeable settings.
virtual void PrepareTitleText()
Set the title actor's input to the latest title (and subtitle) text.
double TextureGridWidth
User-changeable settings.
vtkTimeStamp BuildTime
Internal state used for rendering.
virtual void LayoutAboveRangeSwatch()
Determine the size of the Above Range if it is to be rendered.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void SetFrameProperty(vtkProperty2D *p)
Set/Get the frame property.
bool DrawAboveRangeSwatch
User-changeable settings.
int MaximumWidthInPixels
User-changeable settings.
int NumberOfLabelsBuilt
User-changeable settings.
virtual void LayoutForUnconstrainedFont()
This method sets the title and tick-box size and position for the UnconstrainedFontSize mode.
vtkScalarsToColors * LookupTable
The object this actor illustrates.
virtual void LayoutTicks()
Determine the size and placement of any tick marks to be rendered.
virtual void SetLabelTextProperty(vtkTextProperty *p)
Set/Get the labels text property.
Superclass for mapping scalar values to colors.
An actor that displays text.
Definition: vtkTextActor.h:51
2D text annotation
Definition: vtkTextMapper.h:48
represent text properties.
handles properties associated with a texture map
Definition: vtkTexture.h:66
actor that draws 2D data with texture support
record modification and/or execution time
Definition: vtkTimeStamp.h:33
abstract specification for Viewports
Definition: vtkViewport.h:47
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
@ range
Definition: vtkX3D.h:244
@ size
Definition: vtkX3D.h:259
int vtkTypeBool
Definition: vtkABI.h:69
#define VTK_ORIENT_VERTICAL
#define VTK_ORIENT_HORIZONTAL
#define VTK_INT_MAX
Definition: vtkType.h:155