VTK  9.3.0
vtkScalarBarActor.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
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 VTK_ABI_NAMESPACE_BEGIN
64 class vtkColor3ub;
65 class vtkPolyData;
67 class vtkProperty2D;
68 class vtkScalarsToColors;
70 class vtkTextActor;
71 class vtkTextMapper;
72 class vtkTextProperty;
73 class vtkTexture;
74 class vtkTexturedActor2D;
75 
76 #define VTK_ORIENT_HORIZONTAL 0
77 #define VTK_ORIENT_VERTICAL 1
78 
79 class VTKRENDERINGANNOTATION_EXPORT vtkScalarBarActor : public vtkActor2D
80 {
81 public:
82  vtkTypeMacro(vtkScalarBarActor, vtkActor2D);
83  void PrintSelf(ostream& os, vtkIndent indent) override;
84 
91 
93 
96  int RenderOpaqueGeometry(vtkViewport* viewport) override;
97  int RenderTranslucentPolygonalGeometry(vtkViewport*) override { return 0; }
98  int RenderOverlay(vtkViewport* viewport) override;
100 
105 
112 
118  virtual void GetScalarBarRect(int rect[4], vtkViewport* viewport);
119 
121 
128  vtkGetObjectMacro(LookupTable, vtkScalarsToColors);
130 
132 
139  vtkSetMacro(UseOpacity, vtkTypeBool);
140  vtkGetMacro(UseOpacity, vtkTypeBool);
141  vtkBooleanMacro(UseOpacity, vtkTypeBool);
143 
145 
150  vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_INT_MAX);
151  vtkGetMacro(MaximumNumberOfColors, int);
153 
155 
158  vtkSetClampMacro(NumberOfLabels, int, 0, 64);
159  vtkGetMacro(NumberOfLabels, int);
161 
163 
166  virtual void SetCustomLabels(vtkDoubleArray* labels);
167  vtkGetObjectMacro(CustomLabels, vtkDoubleArray);
169 
171 
175  vtkGetMacro(UseCustomLabels, bool);
176  vtkSetMacro(UseCustomLabels, bool);
177  vtkBooleanMacro(UseCustomLabels, bool);
179 
181 
184  vtkSetClampMacro(Orientation, int, VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
185  vtkGetMacro(Orientation, int);
186  void SetOrientationToHorizontal() { this->SetOrientation(VTK_ORIENT_HORIZONTAL); }
187  void SetOrientationToVertical() { this->SetOrientation(VTK_ORIENT_VERTICAL); }
189 
191 
195  vtkGetObjectMacro(TitleTextProperty, vtkTextProperty);
197 
199 
203  vtkGetObjectMacro(LabelTextProperty, vtkTextProperty);
205 
207 
211  vtkGetObjectMacro(AnnotationTextProperty, vtkTextProperty);
213 
215 
219  vtkSetStringMacro(LabelFormat);
220  vtkGetStringMacro(LabelFormat);
222 
224 
227  vtkSetStringMacro(Title);
228  vtkGetStringMacro(Title);
230 
232 
235  vtkSetStringMacro(ComponentTitle);
236  vtkGetStringMacro(ComponentTitle);
238 
242  void ShallowCopy(vtkProp* prop) override;
243 
245 
248  vtkSetMacro(TextureGridWidth, double);
249  vtkGetMacro(TextureGridWidth, double);
251 
253 
256  vtkGetObjectMacro(TextureActor, vtkTexturedActor2D);
258 
259  enum
260  {
261  PrecedeScalarBar = 0,
262  SucceedScalarBar
263  };
264 
266 
274  vtkSetClampMacro(TextPosition, int, PrecedeScalarBar, SucceedScalarBar);
275  vtkGetMacro(TextPosition, int);
277  {
278  this->SetTextPosition(vtkScalarBarActor::PrecedeScalarBar);
279  }
281  {
282  this->SetTextPosition(vtkScalarBarActor::SucceedScalarBar);
283  }
285 
287 
294  vtkSetMacro(MaximumWidthInPixels, int);
295  vtkGetMacro(MaximumWidthInPixels, int);
296  vtkSetMacro(MaximumHeightInPixels, int);
297  vtkGetMacro(MaximumHeightInPixels, int);
299 
301 
306  vtkSetMacro(AnnotationLeaderPadding, double);
307  vtkGetMacro(AnnotationLeaderPadding, double);
309 
311 
316  vtkSetMacro(DrawAnnotations, vtkTypeBool);
317  vtkGetMacro(DrawAnnotations, vtkTypeBool);
318  vtkBooleanMacro(DrawAnnotations, vtkTypeBool);
320 
322 
327  vtkSetMacro(DrawNanAnnotation, vtkTypeBool);
328  vtkGetMacro(DrawNanAnnotation, vtkTypeBool);
329  vtkBooleanMacro(DrawNanAnnotation, vtkTypeBool);
331 
333 
338  vtkSetMacro(DrawBelowRangeSwatch, bool);
339  vtkGetMacro(DrawBelowRangeSwatch, bool);
340  vtkBooleanMacro(DrawBelowRangeSwatch, bool);
342 
344 
347  vtkSetStringMacro(BelowRangeAnnotation);
348  vtkGetStringMacro(BelowRangeAnnotation);
350 
352 
357  vtkSetMacro(DrawAboveRangeSwatch, bool);
358  vtkGetMacro(DrawAboveRangeSwatch, bool);
359  vtkBooleanMacro(DrawAboveRangeSwatch, bool);
361 
363 
366  vtkSetStringMacro(AboveRangeAnnotation);
367  vtkGetStringMacro(AboveRangeAnnotation);
370 
378  vtkSetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
379  vtkGetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
380  vtkBooleanMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
382 
384 
387  vtkSetStringMacro(NanAnnotation);
388  vtkGetStringMacro(NanAnnotation);
390 
392 
400  vtkSetMacro(AnnotationTextScaling, vtkTypeBool);
401  vtkGetMacro(AnnotationTextScaling, vtkTypeBool);
402  vtkBooleanMacro(AnnotationTextScaling, vtkTypeBool);
404 
406 
410  vtkSetMacro(DrawBackground, vtkTypeBool);
411  vtkGetMacro(DrawBackground, vtkTypeBool);
412  vtkBooleanMacro(DrawBackground, vtkTypeBool);
414 
416 
420  vtkSetMacro(DrawFrame, vtkTypeBool);
421  vtkGetMacro(DrawFrame, vtkTypeBool);
422  vtkBooleanMacro(DrawFrame, vtkTypeBool);
424 
426 
430  vtkSetMacro(DrawColorBar, vtkTypeBool);
431  vtkGetMacro(DrawColorBar, vtkTypeBool);
432  vtkBooleanMacro(DrawColorBar, vtkTypeBool);
434 
436 
439  vtkSetMacro(DrawTickLabels, vtkTypeBool);
440  vtkGetMacro(DrawTickLabels, vtkTypeBool);
441  vtkBooleanMacro(DrawTickLabels, vtkTypeBool);
443 
445 
449  vtkGetObjectMacro(BackgroundProperty, vtkProperty2D);
451 
453 
456  virtual void SetFrameProperty(vtkProperty2D* p);
457  vtkGetObjectMacro(FrameProperty, vtkProperty2D);
459 
461 
465  vtkGetMacro(TextPad, int);
466  vtkSetMacro(TextPad, int);
468 
470 
475  vtkGetMacro(VerticalTitleSeparation, int);
476  vtkSetMacro(VerticalTitleSeparation, int);
478 
480 
484  vtkGetMacro(BarRatio, double);
485  vtkSetClampMacro(BarRatio, double, 0., 1.);
487 
489 
495  vtkGetMacro(TitleRatio, double);
496  vtkSetClampMacro(TitleRatio, double, 0., 1.);
498 
500 
506  vtkSetMacro(UnconstrainedFontSize, bool);
507  vtkGetMacro(UnconstrainedFontSize, bool);
508  vtkBooleanMacro(UnconstrainedFontSize, bool);
510 
511 protected:
513  ~vtkScalarBarActor() override;
514 
539  virtual void RebuildLayout(vtkViewport* viewport);
540 
546  virtual int RebuildLayoutIfNeeded(vtkViewport* viewport);
547 
551  virtual void FreeLayoutStorage();
552 
561  virtual void ComputeFrame();
562 
573 
577  virtual void ComputeSwatchPad();
578 
579  // This method must set this->P->NanSwatchSize and this->P->NanBox.
580  // It may depend on layout performed by ComputeScalarBarThickness.
581  virtual void LayoutNanSwatch();
582 
589  virtual void LayoutBelowRangeSwatch();
590 
597  virtual void LayoutAboveRangeSwatch();
598 
606 
610  virtual void PrepareTitleText();
611 
622  virtual void LayoutTitle();
623 
629 
638  virtual void ComputeScalarBarLength();
639 
651  virtual void LayoutTicks();
652 
660  virtual void LayoutAnnotations();
661 
665  virtual void ConfigureAnnotations();
666 
670  virtual void ConfigureFrame();
671 
675  virtual void DrawBoxes();
676 
680  virtual void ConfigureScalarBar();
681 
685  virtual void ConfigureTitle();
686 
690  virtual void ConfigureTicks();
691 
698  virtual void ConfigureNanSwatch();
699 
704  virtual void ConfigureAboveBelowRangeSwatch(bool above);
705 
714  virtual void EditAnnotations() {}
715 
721  virtual void SizeTitle(double* titleSize, int* size, vtkViewport* viewport);
722 
727  vtkScalarsToColors* lkup, double start, double delta, const double* range);
728 
733  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
739  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
740 
747  vtkDoubleArray* CustomLabels = nullptr;
748  bool UseCustomLabels = false;
749  vtkTypeBool DrawBackground; // off by default
750  vtkTypeBool DrawFrame; // off by default
751  vtkTypeBool DrawColorBar; // on by default
752  vtkTypeBool DrawTickLabels; // on by default
759  char* Title;
761  char* LabelFormat;
762  vtkTypeBool UseOpacity; // off by default
771  int TextPad;
773  double BarRatio;
774  double TitleRatio;
775  bool UnconstrainedFontSize; // off by default
776 
780 
784  int LastSize[2];
785  int LastOrigin[2];
786 
788 
790 
795 
802 
806 
811 
812 private:
813  vtkScalarBarActor(const vtkScalarBarActor&) = delete;
814  void operator=(const vtkScalarBarActor&) = delete;
815 };
816 
817 VTK_ABI_NAMESPACE_END
818 #endif
a actor that draws 2D data
Definition: vtkActor2D.h:44
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:193
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition: vtkIndent.h:38
draw vtkPolyData onto the image plane
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:89
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:55
represent surface properties of a 2D image
Definition: vtkProperty2D.h:39
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:55
2D text annotation
Definition: vtkTextMapper.h:49
represent text properties.
handles properties associated with a texture map
Definition: vtkTexture.h:67
actor that draws 2D data with texture support
record modification and/or execution time
Definition: vtkTimeStamp.h:34
abstract specification for Viewports
Definition: vtkViewport.h:54
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
@ range
Definition: vtkX3D.h:238
@ size
Definition: vtkX3D.h:253
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_ORIENT_VERTICAL
#define VTK_ORIENT_HORIZONTAL
#define VTK_INT_MAX
Definition: vtkType.h:144