VTK  9.3.20240419
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 
164 VTK_ABI_NAMESPACE_BEGIN
165 class vtkColor3ub;
166 class vtkPolyData;
167 class vtkPolyDataMapper2D;
168 class vtkProperty2D;
169 class vtkScalarsToColors;
171 class vtkTextActor;
172 class vtkTextMapper;
173 class vtkTextProperty;
174 class vtkTexture;
175 class vtkTexturedActor2D;
176 
177 #define VTK_ORIENT_HORIZONTAL 0
178 #define VTK_ORIENT_VERTICAL 1
179 
180 class VTKRENDERINGANNOTATION_EXPORT VTK_MARSHALAUTO vtkScalarBarActor : public vtkActor2D
181 {
182 public:
184  void PrintSelf(ostream& os, vtkIndent indent) override;
185 
192 
194 
197  int RenderOpaqueGeometry(vtkViewport* viewport) override;
198  int RenderTranslucentPolygonalGeometry(vtkViewport*) override { return 0; }
199  int RenderOverlay(vtkViewport* viewport) override;
201 
206 
213 
219  virtual void GetScalarBarRect(int rect[4], vtkViewport* viewport);
220 
222 
229  vtkGetObjectMacro(LookupTable, vtkScalarsToColors);
231 
233 
240  vtkSetMacro(UseOpacity, vtkTypeBool);
241  vtkGetMacro(UseOpacity, vtkTypeBool);
242  vtkBooleanMacro(UseOpacity, vtkTypeBool);
244 
246 
251  vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_INT_MAX);
252  vtkGetMacro(MaximumNumberOfColors, int);
254 
256 
259  vtkSetClampMacro(NumberOfLabels, int, 0, 64);
260  vtkGetMacro(NumberOfLabels, int);
262 
264 
267  virtual void SetCustomLabels(vtkDoubleArray* labels);
268  vtkGetObjectMacro(CustomLabels, vtkDoubleArray);
270 
272 
276  vtkGetMacro(UseCustomLabels, bool);
277  vtkSetMacro(UseCustomLabels, bool);
278  vtkBooleanMacro(UseCustomLabels, bool);
280 
282 
285  vtkSetClampMacro(Orientation, int, VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
286  vtkGetMacro(Orientation, int);
287  void SetOrientationToHorizontal() { this->SetOrientation(VTK_ORIENT_HORIZONTAL); }
288  void SetOrientationToVertical() { this->SetOrientation(VTK_ORIENT_VERTICAL); }
290 
292 
295  vtkGetMacro(ForceVerticalTitle, bool);
296  vtkSetMacro(ForceVerticalTitle, bool);
298 
300 
304  vtkGetObjectMacro(TitleTextProperty, vtkTextProperty);
306 
308 
312  vtkGetObjectMacro(LabelTextProperty, vtkTextProperty);
314 
316 
320  vtkGetObjectMacro(AnnotationTextProperty, vtkTextProperty);
322 
324 
328  vtkSetStringMacro(LabelFormat);
329  vtkGetStringMacro(LabelFormat);
331 
333 
336  vtkSetStringMacro(Title);
337  vtkGetStringMacro(Title);
339 
341 
344  vtkSetStringMacro(ComponentTitle);
345  vtkGetStringMacro(ComponentTitle);
347 
351  void ShallowCopy(vtkProp* prop) override;
352 
354 
357  vtkSetMacro(TextureGridWidth, double);
358  vtkGetMacro(TextureGridWidth, double);
360 
362 
365  vtkGetObjectMacro(TextureActor, vtkTexturedActor2D);
367 
368  enum
369  {
370  PrecedeScalarBar = 0,
371  SucceedScalarBar
372  };
373 
375 
383  vtkSetClampMacro(TextPosition, int, PrecedeScalarBar, SucceedScalarBar);
384  vtkGetMacro(TextPosition, int);
386  {
387  this->SetTextPosition(vtkScalarBarActor::PrecedeScalarBar);
388  }
390  {
391  this->SetTextPosition(vtkScalarBarActor::SucceedScalarBar);
392  }
394 
396 
403  vtkSetMacro(MaximumWidthInPixels, int);
404  vtkGetMacro(MaximumWidthInPixels, int);
405  vtkSetMacro(MaximumHeightInPixels, int);
406  vtkGetMacro(MaximumHeightInPixels, int);
408 
410 
415  vtkSetMacro(AnnotationLeaderPadding, double);
416  vtkGetMacro(AnnotationLeaderPadding, double);
418 
420 
425  vtkSetMacro(DrawAnnotations, vtkTypeBool);
426  vtkGetMacro(DrawAnnotations, vtkTypeBool);
427  vtkBooleanMacro(DrawAnnotations, vtkTypeBool);
429 
431 
436  vtkSetMacro(DrawNanAnnotation, vtkTypeBool);
437  vtkGetMacro(DrawNanAnnotation, vtkTypeBool);
438  vtkBooleanMacro(DrawNanAnnotation, vtkTypeBool);
440 
442 
447  vtkSetMacro(DrawBelowRangeSwatch, bool);
448  vtkGetMacro(DrawBelowRangeSwatch, bool);
449  vtkBooleanMacro(DrawBelowRangeSwatch, bool);
451 
453 
456  vtkSetStringMacro(BelowRangeAnnotation);
457  vtkGetStringMacro(BelowRangeAnnotation);
459 
461 
466  vtkSetMacro(DrawAboveRangeSwatch, bool);
467  vtkGetMacro(DrawAboveRangeSwatch, bool);
468  vtkBooleanMacro(DrawAboveRangeSwatch, bool);
470 
472 
475  vtkSetStringMacro(AboveRangeAnnotation);
476  vtkGetStringMacro(AboveRangeAnnotation);
479 
487  vtkSetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
488  vtkGetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
489  vtkBooleanMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
491 
493 
496  vtkSetStringMacro(NanAnnotation);
497  vtkGetStringMacro(NanAnnotation);
499 
501 
509  vtkSetMacro(AnnotationTextScaling, vtkTypeBool);
510  vtkGetMacro(AnnotationTextScaling, vtkTypeBool);
511  vtkBooleanMacro(AnnotationTextScaling, vtkTypeBool);
513 
515 
519  vtkSetMacro(DrawBackground, vtkTypeBool);
520  vtkGetMacro(DrawBackground, vtkTypeBool);
521  vtkBooleanMacro(DrawBackground, vtkTypeBool);
523 
525 
529  vtkSetMacro(DrawFrame, vtkTypeBool);
530  vtkGetMacro(DrawFrame, vtkTypeBool);
531  vtkBooleanMacro(DrawFrame, vtkTypeBool);
533 
535 
539  vtkSetMacro(DrawColorBar, vtkTypeBool);
540  vtkGetMacro(DrawColorBar, vtkTypeBool);
541  vtkBooleanMacro(DrawColorBar, vtkTypeBool);
543 
545 
548  vtkSetMacro(DrawTickLabels, vtkTypeBool);
549  vtkGetMacro(DrawTickLabels, vtkTypeBool);
550  vtkBooleanMacro(DrawTickLabels, vtkTypeBool);
552 
554 
558  vtkGetObjectMacro(BackgroundProperty, vtkProperty2D);
560 
562 
565  virtual void SetFrameProperty(vtkProperty2D* p);
566  vtkGetObjectMacro(FrameProperty, vtkProperty2D);
568 
570 
574  vtkGetMacro(TextPad, int);
575  vtkSetMacro(TextPad, int);
577 
579 
584  vtkGetMacro(VerticalTitleSeparation, int);
585  vtkSetMacro(VerticalTitleSeparation, int);
587 
589 
593  vtkGetMacro(BarRatio, double);
594  vtkSetClampMacro(BarRatio, double, 0., 1.);
596 
598 
604  vtkGetMacro(TitleRatio, double);
605  vtkSetClampMacro(TitleRatio, double, 0., 1.);
607 
609 
615  vtkSetMacro(UnconstrainedFontSize, bool);
616  vtkGetMacro(UnconstrainedFontSize, bool);
617  vtkBooleanMacro(UnconstrainedFontSize, bool);
619 
620 protected:
622  ~vtkScalarBarActor() override;
623 
648  virtual void RebuildLayout(vtkViewport* viewport);
649 
655  virtual int RebuildLayoutIfNeeded(vtkViewport* viewport);
656 
660  virtual void FreeLayoutStorage();
661 
670  virtual void ComputeFrame();
671 
682 
686  virtual void ComputeSwatchPad();
687 
688  // This method must set this->P->NanSwatchSize and this->P->NanBox.
689  // It may depend on layout performed by ComputeScalarBarThickness.
690  virtual void LayoutNanSwatch();
691 
698  virtual void LayoutBelowRangeSwatch();
699 
706  virtual void LayoutAboveRangeSwatch();
707 
715 
719  virtual void PrepareTitleText();
720 
731  virtual void LayoutTitle();
732 
738 
747  virtual void ComputeScalarBarLength();
748 
760  virtual void LayoutTicks();
761 
769  virtual void LayoutAnnotations();
770 
774  virtual void ConfigureAnnotations();
775 
779  virtual void ConfigureFrame();
780 
784  virtual void DrawBoxes();
785 
789  virtual void ConfigureScalarBar();
790 
794  virtual void ConfigureTitle();
795 
799  virtual void ConfigureTicks();
800 
807  virtual void ConfigureNanSwatch();
808 
813  virtual void ConfigureAboveBelowRangeSwatch(bool above);
814 
823  virtual void EditAnnotations() {}
824 
830  virtual void SizeTitle(double* titleSize, int* size, vtkViewport* viewport);
831 
836  vtkScalarsToColors* lkup, double start, double delta, const double* range);
837 
842  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
848  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
849 
856  vtkDoubleArray* CustomLabels = nullptr;
857  bool UseCustomLabels = false;
858  vtkTypeBool DrawBackground; // off by default
859  vtkTypeBool DrawFrame; // off by default
860  vtkTypeBool DrawColorBar; // on by default
861  vtkTypeBool DrawTickLabels; // on by default
868  char* Title;
870  char* LabelFormat;
871  vtkTypeBool UseOpacity; // off by default
880  int TextPad;
882  double BarRatio;
883  double TitleRatio;
884  bool UnconstrainedFontSize; // off by default
885  bool ForceVerticalTitle; // off by default
886 
890 
894  int LastSize[2];
895  int LastOrigin[2];
896 
898 
900 
905 
912 
916 
921 
922 private:
923  vtkScalarBarActor(const vtkScalarBarActor&) = delete;
924  void operator=(const vtkScalarBarActor&) = delete;
925 };
926 
927 VTK_ABI_NAMESPACE_END
928 #endif
a actor that draws 2D data
Definition: vtkActor2D.h:145
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:203
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition: vtkIndent.h:108
draw vtkPolyData onto the image plane
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:181
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:66
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.
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.
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.
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:155
2D text annotation
represent text properties.
handles properties associated with a texture map
Definition: vtkTexture.h:167
actor that draws 2D data with texture support
record modification and/or execution time
Definition: vtkTimeStamp.h:44
abstract specification for Viewports
Definition: vtkViewport.h:65
window superclass for vtkRenderWindow
Definition: vtkWindow.h:48
@ 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
#define VTK_MARSHALAUTO