VTK  9.5.20250812
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
156#ifndef vtkScalarBarActor_h
157#define vtkScalarBarActor_h
158
159#include "vtkActor2D.h"
160#include "vtkDoubleArray.h" // for ivars
161#include "vtkRenderingAnnotationModule.h" // For export macro
162#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
163
164VTK_ABI_NAMESPACE_BEGIN
165class vtkColor3ub;
167class vtkPolyData;
169class vtkProperty2D;
172class vtkTextActor;
173class vtkTextMapper;
174class vtkTextProperty;
175class vtkTexture;
177
178#define VTK_ORIENT_HORIZONTAL 0
179#define VTK_ORIENT_VERTICAL 1
180
181class VTKRENDERINGANNOTATION_EXPORT VTK_MARSHALAUTO vtkScalarBarActor : public vtkActor2D
182{
183public:
185 void PrintSelf(ostream& os, vtkIndent indent) override;
186
193
195
198 int RenderOpaqueGeometry(vtkViewport* viewport) override;
200 int RenderOverlay(vtkViewport* viewport) override;
202
207
214
220 virtual void GetScalarBarRect(int rect[4], vtkViewport* viewport);
221
223
230 vtkGetObjectMacro(LookupTable, vtkScalarsToColors);
232
234
242 vtkGetObjectMacro(OpacityFunction, vtkPiecewiseFunction);
244
246
258 vtkSetMacro(UseOpacity, vtkTypeBool);
259 vtkGetMacro(UseOpacity, vtkTypeBool);
260 vtkBooleanMacro(UseOpacity, vtkTypeBool);
262
264
269 vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_INT_MAX);
270 vtkGetMacro(MaximumNumberOfColors, int);
272
274
277 vtkSetClampMacro(NumberOfLabels, int, 0, 64);
278 vtkGetMacro(NumberOfLabels, int);
280
282
285 virtual void SetCustomLabels(vtkDoubleArray* labels);
286 vtkGetObjectMacro(CustomLabels, vtkDoubleArray);
288
290
294 vtkGetMacro(UseCustomLabels, bool);
295 vtkSetMacro(UseCustomLabels, bool);
296 vtkBooleanMacro(UseCustomLabels, bool);
298
300
303 vtkSetClampMacro(Orientation, int, VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
304 vtkGetMacro(Orientation, int);
305 void SetOrientationToHorizontal() { this->SetOrientation(VTK_ORIENT_HORIZONTAL); }
306 void SetOrientationToVertical() { this->SetOrientation(VTK_ORIENT_VERTICAL); }
308
310
313 vtkGetMacro(ForceVerticalTitle, bool);
314 vtkSetMacro(ForceVerticalTitle, bool);
316
318
322 vtkGetObjectMacro(TitleTextProperty, vtkTextProperty);
324
326
330 vtkGetObjectMacro(LabelTextProperty, vtkTextProperty);
332
334
338 vtkGetObjectMacro(AnnotationTextProperty, vtkTextProperty);
340
342
346 vtkSetStringMacro(LabelFormat);
347 vtkGetStringMacro(LabelFormat);
349
351
354 vtkSetStringMacro(Title);
355 vtkGetStringMacro(Title);
357
359
362 vtkSetStringMacro(ComponentTitle);
363 vtkGetStringMacro(ComponentTitle);
365
369 void ShallowCopy(vtkProp* prop) override;
370
372
375 vtkSetMacro(TextureGridWidth, double);
376 vtkGetMacro(TextureGridWidth, double);
378
380
383 vtkGetObjectMacro(TextureActor, vtkTexturedActor2D);
385
386 enum
387 {
388 PrecedeScalarBar = 0,
389 SucceedScalarBar
390 };
391
393
401 vtkSetClampMacro(TextPosition, int, PrecedeScalarBar, SucceedScalarBar);
402 vtkGetMacro(TextPosition, int);
404 {
405 this->SetTextPosition(vtkScalarBarActor::PrecedeScalarBar);
406 }
408 {
409 this->SetTextPosition(vtkScalarBarActor::SucceedScalarBar);
410 }
412
414
421 vtkSetMacro(MaximumWidthInPixels, int);
422 vtkGetMacro(MaximumWidthInPixels, int);
423 vtkSetMacro(MaximumHeightInPixels, int);
424 vtkGetMacro(MaximumHeightInPixels, int);
426
428
433 vtkSetMacro(AnnotationLeaderPadding, double);
434 vtkGetMacro(AnnotationLeaderPadding, double);
436
438
443 vtkSetMacro(DrawAnnotations, vtkTypeBool);
444 vtkGetMacro(DrawAnnotations, vtkTypeBool);
445 vtkBooleanMacro(DrawAnnotations, vtkTypeBool);
447
449
454 vtkSetMacro(DrawNanAnnotation, vtkTypeBool);
455 vtkGetMacro(DrawNanAnnotation, vtkTypeBool);
456 vtkBooleanMacro(DrawNanAnnotation, vtkTypeBool);
458
460
465 vtkSetMacro(DrawBelowRangeSwatch, bool);
466 vtkGetMacro(DrawBelowRangeSwatch, bool);
467 vtkBooleanMacro(DrawBelowRangeSwatch, bool);
469
471
474 vtkSetStringMacro(BelowRangeAnnotation);
475 vtkGetStringMacro(BelowRangeAnnotation);
477
479
484 vtkSetMacro(DrawAboveRangeSwatch, bool);
485 vtkGetMacro(DrawAboveRangeSwatch, bool);
486 vtkBooleanMacro(DrawAboveRangeSwatch, bool);
488
490
493 vtkSetStringMacro(AboveRangeAnnotation);
494 vtkGetStringMacro(AboveRangeAnnotation);
497
505 vtkSetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
506 vtkGetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
507 vtkBooleanMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
509
511
514 vtkSetStringMacro(NanAnnotation);
515 vtkGetStringMacro(NanAnnotation);
517
519
527 vtkSetMacro(AnnotationTextScaling, vtkTypeBool);
528 vtkGetMacro(AnnotationTextScaling, vtkTypeBool);
529 vtkBooleanMacro(AnnotationTextScaling, vtkTypeBool);
531
533
537 vtkSetMacro(DrawBackground, vtkTypeBool);
538 vtkGetMacro(DrawBackground, vtkTypeBool);
539 vtkBooleanMacro(DrawBackground, vtkTypeBool);
541
543
547 vtkSetMacro(DrawFrame, vtkTypeBool);
548 vtkGetMacro(DrawFrame, vtkTypeBool);
549 vtkBooleanMacro(DrawFrame, vtkTypeBool);
551
553
557 vtkSetMacro(DrawColorBar, vtkTypeBool);
558 vtkGetMacro(DrawColorBar, vtkTypeBool);
559 vtkBooleanMacro(DrawColorBar, vtkTypeBool);
561
563
566 vtkSetMacro(DrawTickLabels, vtkTypeBool);
567 vtkGetMacro(DrawTickLabels, vtkTypeBool);
568 vtkBooleanMacro(DrawTickLabels, vtkTypeBool);
570
572
576 vtkGetObjectMacro(BackgroundProperty, vtkProperty2D);
578
580
584 vtkGetObjectMacro(FrameProperty, vtkProperty2D);
586
588
592 vtkGetMacro(TextPad, int);
593 vtkSetMacro(TextPad, int);
595
597
602 vtkGetMacro(VerticalTitleSeparation, int);
603 vtkSetMacro(VerticalTitleSeparation, int);
605
607
611 vtkGetMacro(BarRatio, double);
612 vtkSetClampMacro(BarRatio, double, 0., 1.);
614
616
622 vtkGetMacro(TitleRatio, double);
623 vtkSetClampMacro(TitleRatio, double, 0., 1.);
625
627
633 vtkSetMacro(UnconstrainedFontSize, bool);
634 vtkGetMacro(UnconstrainedFontSize, bool);
635 vtkBooleanMacro(UnconstrainedFontSize, bool);
637
643
644protected:
647
672 virtual void RebuildLayout(vtkViewport* viewport);
673
679 virtual int RebuildLayoutIfNeeded(vtkViewport* viewport);
680
684 virtual void FreeLayoutStorage();
685
694 virtual void ComputeFrame();
695
706
710 virtual void ComputeSwatchPad();
711
712 // This method must set this->P->NanSwatchSize and this->P->NanBox.
713 // It may depend on layout performed by ComputeScalarBarThickness.
714 virtual void LayoutNanSwatch();
715
723
731
739
743 virtual void PrepareTitleText();
744
755 virtual void LayoutTitle();
756
762
772
784 virtual void LayoutTicks();
785
793 virtual void LayoutAnnotations();
794
798 virtual void ConfigureAnnotations();
799
803 virtual void ConfigureFrame();
804
808 virtual void DrawBoxes();
809
813 virtual void ConfigureScalarBar();
814
818 virtual void ConfigureTitle();
819
823 virtual void ConfigureTicks();
824
831 virtual void ConfigureNanSwatch();
832
837 virtual void ConfigureAboveBelowRangeSwatch(bool above);
838
847 virtual void EditAnnotations() {}
848
854 virtual void SizeTitle(double* titleSize, int* size, vtkViewport* viewport);
855
860 vtkScalarsToColors* lkup, double start, double delta, const double* range);
861
866 double barX, double barY, double barWidth, double barHeight, double delta, double pad);
872 double barX, double barY, double barWidth, double barHeight, double delta, double pad);
873
880 vtkDoubleArray* CustomLabels = nullptr;
881 bool UseCustomLabels = false;
882 vtkTypeBool DrawBackground; // off by default
883 vtkTypeBool DrawFrame; // off by default
884 vtkTypeBool DrawColorBar; // on by default
885 vtkTypeBool DrawTickLabels; // on by default
892 char* Title;
895 vtkTypeBool UseOpacity; // off by default
906 double BarRatio;
908 bool UnconstrainedFontSize; // off by default
909 bool ForceVerticalTitle; // off by default
910
914
918 int LastSize[2];
919 int LastOrigin[2];
920
922
925
930
937
941
946
947private:
948 vtkScalarBarActor(const vtkScalarBarActor&) = delete;
949 void operator=(const vtkScalarBarActor&) = delete;
950};
951
952VTK_ABI_NAMESPACE_END
953#endif
a actor that draws 2D data
Definition vtkActor2D.h:145
Some derived classes for the different colors commonly used.
Definition vtkColor.h:203
perform coordinate transformation, and represent position, in a variety of vtk coordinate systems
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition vtkIndent.h:108
Defines a 1D piecewise function.
draw vtkPolyData onto the image plane
concrete dataset represents vertices, lines, polygons, and triangle strips
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:69
represent surface properties of a 2D image
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.
virtual void SetOpacityFunction(vtkPiecewiseFunction *)
Set/Get the piecewise function that denotes opacity function to map values through.
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.
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.
bool ForceVerticalTitle
User-changeable settings.
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.
void SetPositionCoordinate(vtkCoordinate *pos) override
Set the PositionCoordinate instance of vtkCoordinate.
vtkPiecewiseFunction * OpacityFunction
The opacity function if UseOpacity is true.
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.
static vtkScalarBarActor * New()
Instantiate object with 64 maximum colors; 5 labels; %%-#6.3g label format, no title,...
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.
2D text annotation
represent text properties.
handles properties associated with a texture map
Definition vtkTexture.h:168
actor that draws 2D data with texture support
record modification and/or execution time
abstract specification for Viewports
Definition vtkViewport.h:66
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_ORIENT_VERTICAL
#define VTK_ORIENT_HORIZONTAL
#define VTK_INT_MAX
Definition vtkType.h:161
#define VTK_MARSHALAUTO