VTK  9.3.1
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
47 #ifndef vtkScalarBarActor_h
48 #define vtkScalarBarActor_h
49 
50 #include "vtkActor2D.h"
51 #include "vtkDoubleArray.h" // for ivars
52 #include "vtkRenderingAnnotationModule.h" // For export macro
53 
54 VTK_ABI_NAMESPACE_BEGIN
55 class vtkColor3ub;
56 class vtkPolyData;
58 class vtkProperty2D;
59 class vtkScalarsToColors;
61 class vtkTextActor;
62 class vtkTextMapper;
63 class vtkTextProperty;
64 class vtkTexture;
65 class vtkTexturedActor2D;
66 
67 #define VTK_ORIENT_HORIZONTAL 0
68 #define VTK_ORIENT_VERTICAL 1
69 
70 class VTKRENDERINGANNOTATION_EXPORT vtkScalarBarActor : public vtkActor2D
71 {
72 public:
73  vtkTypeMacro(vtkScalarBarActor, vtkActor2D);
74  void PrintSelf(ostream& os, vtkIndent indent) override;
75 
81  static vtkScalarBarActor* New();
82 
84 
87  int RenderOpaqueGeometry(vtkViewport* viewport) override;
88  int RenderTranslucentPolygonalGeometry(vtkViewport*) override { return 0; }
89  int RenderOverlay(vtkViewport* viewport) override;
91 
96 
102  void ReleaseGraphicsResources(vtkWindow*) override;
103 
109  virtual void GetScalarBarRect(int rect[4], vtkViewport* viewport);
110 
112 
118  virtual void SetLookupTable(vtkScalarsToColors*);
119  vtkGetObjectMacro(LookupTable, vtkScalarsToColors);
121 
123 
130  vtkSetMacro(UseOpacity, vtkTypeBool);
131  vtkGetMacro(UseOpacity, vtkTypeBool);
132  vtkBooleanMacro(UseOpacity, vtkTypeBool);
134 
136 
141  vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_INT_MAX);
142  vtkGetMacro(MaximumNumberOfColors, int);
144 
146 
149  vtkSetClampMacro(NumberOfLabels, int, 0, 64);
150  vtkGetMacro(NumberOfLabels, int);
152 
154 
157  virtual void SetCustomLabels(vtkDoubleArray* labels);
158  vtkGetObjectMacro(CustomLabels, vtkDoubleArray);
160 
162 
166  vtkGetMacro(UseCustomLabels, bool);
167  vtkSetMacro(UseCustomLabels, bool);
168  vtkBooleanMacro(UseCustomLabels, bool);
170 
172 
175  vtkSetClampMacro(Orientation, int, VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
176  vtkGetMacro(Orientation, int);
177  void SetOrientationToHorizontal() { this->SetOrientation(VTK_ORIENT_HORIZONTAL); }
178  void SetOrientationToVertical() { this->SetOrientation(VTK_ORIENT_VERTICAL); }
180 
182 
185  virtual void SetTitleTextProperty(vtkTextProperty* p);
186  vtkGetObjectMacro(TitleTextProperty, vtkTextProperty);
188 
190 
193  virtual void SetLabelTextProperty(vtkTextProperty* p);
194  vtkGetObjectMacro(LabelTextProperty, vtkTextProperty);
196 
198 
201  virtual void SetAnnotationTextProperty(vtkTextProperty* p);
202  vtkGetObjectMacro(AnnotationTextProperty, vtkTextProperty);
204 
206 
210  vtkSetStringMacro(LabelFormat);
211  vtkGetStringMacro(LabelFormat);
213 
215 
218  vtkSetStringMacro(Title);
219  vtkGetStringMacro(Title);
221 
223 
226  vtkSetStringMacro(ComponentTitle);
227  vtkGetStringMacro(ComponentTitle);
229 
233  void ShallowCopy(vtkProp* prop) override;
234 
236 
239  vtkSetMacro(TextureGridWidth, double);
240  vtkGetMacro(TextureGridWidth, double);
242 
244 
247  vtkGetObjectMacro(TextureActor, vtkTexturedActor2D);
249 
250  enum
251  {
252  PrecedeScalarBar = 0,
253  SucceedScalarBar
254  };
255 
257 
265  vtkSetClampMacro(TextPosition, int, PrecedeScalarBar, SucceedScalarBar);
266  vtkGetMacro(TextPosition, int);
268  {
269  this->SetTextPosition(vtkScalarBarActor::PrecedeScalarBar);
270  }
272  {
273  this->SetTextPosition(vtkScalarBarActor::SucceedScalarBar);
274  }
276 
278 
285  vtkSetMacro(MaximumWidthInPixels, int);
286  vtkGetMacro(MaximumWidthInPixels, int);
287  vtkSetMacro(MaximumHeightInPixels, int);
288  vtkGetMacro(MaximumHeightInPixels, int);
290 
292 
297  vtkSetMacro(AnnotationLeaderPadding, double);
298  vtkGetMacro(AnnotationLeaderPadding, double);
300 
302 
307  vtkSetMacro(DrawAnnotations, vtkTypeBool);
308  vtkGetMacro(DrawAnnotations, vtkTypeBool);
309  vtkBooleanMacro(DrawAnnotations, vtkTypeBool);
311 
313 
318  vtkSetMacro(DrawNanAnnotation, vtkTypeBool);
319  vtkGetMacro(DrawNanAnnotation, vtkTypeBool);
320  vtkBooleanMacro(DrawNanAnnotation, vtkTypeBool);
322 
324 
329  vtkSetMacro(DrawBelowRangeSwatch, bool);
330  vtkGetMacro(DrawBelowRangeSwatch, bool);
331  vtkBooleanMacro(DrawBelowRangeSwatch, bool);
333 
335 
338  vtkSetStringMacro(BelowRangeAnnotation);
339  vtkGetStringMacro(BelowRangeAnnotation);
341 
343 
348  vtkSetMacro(DrawAboveRangeSwatch, bool);
349  vtkGetMacro(DrawAboveRangeSwatch, bool);
350  vtkBooleanMacro(DrawAboveRangeSwatch, bool);
352 
354 
357  vtkSetStringMacro(AboveRangeAnnotation);
358  vtkGetStringMacro(AboveRangeAnnotation);
361 
369  vtkSetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
370  vtkGetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
371  vtkBooleanMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
373 
375 
378  vtkSetStringMacro(NanAnnotation);
379  vtkGetStringMacro(NanAnnotation);
381 
383 
391  vtkSetMacro(AnnotationTextScaling, vtkTypeBool);
392  vtkGetMacro(AnnotationTextScaling, vtkTypeBool);
393  vtkBooleanMacro(AnnotationTextScaling, vtkTypeBool);
395 
397 
401  vtkSetMacro(DrawBackground, vtkTypeBool);
402  vtkGetMacro(DrawBackground, vtkTypeBool);
403  vtkBooleanMacro(DrawBackground, vtkTypeBool);
405 
407 
411  vtkSetMacro(DrawFrame, vtkTypeBool);
412  vtkGetMacro(DrawFrame, vtkTypeBool);
413  vtkBooleanMacro(DrawFrame, vtkTypeBool);
415 
417 
421  vtkSetMacro(DrawColorBar, vtkTypeBool);
422  vtkGetMacro(DrawColorBar, vtkTypeBool);
423  vtkBooleanMacro(DrawColorBar, vtkTypeBool);
425 
427 
430  vtkSetMacro(DrawTickLabels, vtkTypeBool);
431  vtkGetMacro(DrawTickLabels, vtkTypeBool);
432  vtkBooleanMacro(DrawTickLabels, vtkTypeBool);
434 
436 
439  virtual void SetBackgroundProperty(vtkProperty2D* p);
440  vtkGetObjectMacro(BackgroundProperty, vtkProperty2D);
442 
444 
447  virtual void SetFrameProperty(vtkProperty2D* p);
448  vtkGetObjectMacro(FrameProperty, vtkProperty2D);
450 
452 
456  vtkGetMacro(TextPad, int);
457  vtkSetMacro(TextPad, int);
459 
461 
466  vtkGetMacro(VerticalTitleSeparation, int);
467  vtkSetMacro(VerticalTitleSeparation, int);
469 
471 
475  vtkGetMacro(BarRatio, double);
476  vtkSetClampMacro(BarRatio, double, 0., 1.);
478 
480 
486  vtkGetMacro(TitleRatio, double);
487  vtkSetClampMacro(TitleRatio, double, 0., 1.);
489 
491 
497  vtkSetMacro(UnconstrainedFontSize, bool);
498  vtkGetMacro(UnconstrainedFontSize, bool);
499  vtkBooleanMacro(UnconstrainedFontSize, bool);
501 
502 protected:
504  ~vtkScalarBarActor() override;
505 
530  virtual void RebuildLayout(vtkViewport* viewport);
531 
537  virtual int RebuildLayoutIfNeeded(vtkViewport* viewport);
538 
542  virtual void FreeLayoutStorage();
543 
552  virtual void ComputeFrame();
553 
563  virtual void ComputeScalarBarThickness();
564 
568  virtual void ComputeSwatchPad();
569 
570  // This method must set this->P->NanSwatchSize and this->P->NanBox.
571  // It may depend on layout performed by ComputeScalarBarThickness.
572  virtual void LayoutNanSwatch();
573 
580  virtual void LayoutBelowRangeSwatch();
581 
588  virtual void LayoutAboveRangeSwatch();
589 
596  virtual void LayoutAboveRangeSwatchPosn();
597 
601  virtual void PrepareTitleText();
602 
613  virtual void LayoutTitle();
614 
619  virtual void LayoutForUnconstrainedFont();
620 
629  virtual void ComputeScalarBarLength();
630 
642  virtual void LayoutTicks();
643 
651  virtual void LayoutAnnotations();
652 
656  virtual void ConfigureAnnotations();
657 
661  virtual void ConfigureFrame();
662 
666  virtual void DrawBoxes();
667 
671  virtual void ConfigureScalarBar();
672 
676  virtual void ConfigureTitle();
677 
681  virtual void ConfigureTicks();
682 
689  virtual void ConfigureNanSwatch();
690 
695  virtual void ConfigureAboveBelowRangeSwatch(bool above);
696 
705  virtual void EditAnnotations() {}
706 
712  virtual void SizeTitle(double* titleSize, int* size, vtkViewport* viewport);
713 
717  int MapAnnotationLabels(
718  vtkScalarsToColors* lkup, double start, double delta, const double* range);
719 
723  int PlaceAnnotationsVertically(
724  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
729  int PlaceAnnotationsHorizontally(
730  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
731 
738  vtkDoubleArray* CustomLabels = nullptr;
739  bool UseCustomLabels = false;
740  vtkTypeBool DrawBackground; // off by default
741  vtkTypeBool DrawFrame; // off by default
742  vtkTypeBool DrawColorBar; // on by default
743  vtkTypeBool DrawTickLabels; // on by default
750  char* Title;
752  char* LabelFormat;
753  vtkTypeBool UseOpacity; // off by default
762  int TextPad;
764  double BarRatio;
765  double TitleRatio;
766  bool UnconstrainedFontSize; // off by default
767 
771 
775  int LastSize[2];
776  int LastOrigin[2];
777 
779 
781 
786 
793 
797 
801 
803 private:
804  vtkScalarBarActor(const vtkScalarBarActor&) = delete;
805  void operator=(const vtkScalarBarActor&) = delete;
806 };
807 
808 VTK_ABI_NAMESPACE_END
809 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:45
int TextPad
User-changeable settings.
int MaximumWidthInPixels
User-changeable settings.
virtual void EditAnnotations()
Subclasses may override this method to alter this->P->Labels, allowing the addition and removal of an...
double TitleRatio
User-changeable settings.
int RenderOverlay(vtkViewport *viewport) override
Support the standard render methods.
vtkTypeBool FixedAnnotationLeaderLineColor
User-changeable settings.
actor that draws 2D data with texture support
vtkPolyDataMapper2D * ScalarBarMapper
Mapper for ScalarBar.
abstract specification for Viewports
Definition: vtkViewport.h:44
virtual void SetTextPositionToPrecedeScalarBar()
Should the title and tick marks precede the scalar bar or succeed it? This is measured along the view...
vtkScalarsToColors * LookupTable
The object this actor illustrates.
#define VTK_INT_MAX
Definition: vtkType.h:144
vtkPolyDataMapper2D * BackgroundMapper
Mapper for Background.
a actor that draws 2D data
Definition: vtkActor2D.h:34
record modification and/or execution time
Definition: vtkTimeStamp.h:24
Internal state for the scalar bar actor shared with subclasses.
int NumberOfLabelsBuilt
User-changeable settings.
vtkActor2D * FrameActor
Actor for Frame.
Create a scalar bar with labels.
int VerticalTitleSeparation
User-changeable settings.
char * AboveRangeAnnotation
User-changeable settings.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
double TextureGridWidth
User-changeable settings.
void ShallowCopy(vtkProp *prop) override
Shallow copy of this vtkActor2D.
vtkTexture * Texture
Color data for TexturePolyData.
vtkTypeBool AnnotationTextScaling
User-changeable settings.
vtkTypeBool DrawAnnotations
User-changeable settings.
2D text annotation
Definition: vtkTextMapper.h:39
dynamic, self-adjusting array of double
char * BelowRangeAnnotation
User-changeable settings.
char * ComponentTitle
User-changeable settings.
#define VTK_ORIENT_VERTICAL
int MaximumHeightInPixels
User-changeable settings.
int RenderTranslucentPolygonalGeometry(vtkViewport *) override
Draw the scalar bar and annotation text to the screen.
int vtkTypeBool
Definition: vtkABI.h:64
char * Title
User-changeable settings.
Superclass for mapping scalar values to colors.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:27
vtkActor2D * BackgroundActor
Actor for Background.
An actor that displays text.
Definition: vtkTextActor.h:45
#define VTK_ORIENT_HORIZONTAL
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:183
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this actor.
a simple class to control print indentation
Definition: vtkIndent.h:28
char * LabelFormat
User-changeable settings.
vtkScalarBarActorInternal * P
Containers shared with subclasses.
int NumberOfLabels
User-changeable settings.
static vtkActor2D * New()
Creates an actor2D with the following defaults: position (0,0) (coordinate system is viewport); at la...
double AnnotationLeaderPadding
User-changeable settings.
handles properties associated with a texture map
Definition: vtkTexture.h:57
int Orientation
User-changeable settings.
int TextPosition
User-changeable settings.
vtkPolyData * ScalarBar
Polygon(s) colored by LookupTable.
vtkTypeBool UseOpacity
User-changeable settings.
bool DrawBelowRangeSwatch
User-changeable settings.
vtkProperty2D * BackgroundProperty
User-changeable settings.
vtkActor2D * ScalarBarActor
Actor for ScalarBar.
represent text properties.
vtkPolyData * Background
Polygon used to fill the background.
vtkTextProperty * LabelTextProperty
Font for tick labels.
vtkTimeStamp BuildTime
Internal state used for rendering.
vtkTextProperty * TitleTextProperty
Font for the legend title.
int MaximumNumberOfColors
User-changeable settings.
vtkTypeBool HasTranslucentPolygonalGeometry() override
Does this prop have some translucent polygonal geometry?
char * NanAnnotation
User-changeable settings.
vtkTypeBool DrawBackground
User-changeable settings.
vtkTypeBool DrawColorBar
User-changeable settings.
double BarRatio
User-changeable settings.
vtkTypeBool DrawFrame
User-changeable settings.
int RenderOpaqueGeometry(vtkViewport *viewport) override
Support the standard render methods.
vtkTextProperty * AnnotationTextProperty
Font for annotation labels.
vtkTextActor * TitleActor
The legend title text renderer.
vtkPolyDataMapper2D * FrameMapper
Mapper for Frame.
represent surface properties of a 2D image
Definition: vtkProperty2D.h:29
virtual void SetTextPositionToSucceedScalarBar()
Should the title and tick marks precede the scalar bar or succeed it? This is measured along the view...
void SetOrientationToVertical()
Control the orientation of the scalar bar.
bool DrawAboveRangeSwatch
User-changeable settings.
void SetOrientationToHorizontal()
Control the orientation of the scalar bar.
vtkProperty2D * FrameProperty
User-changeable settings.
bool UnconstrainedFontSize
User-changeable settings.
vtkPolyData * Frame
Polyline used to highlight frame.
vtkTypeBool DrawTickLabels
User-changeable settings.
draw vtkPolyData onto the image plane
vtkPolyData * TexturePolyData
Polygon colored when UseOpacity is true.
vtkTypeBool DrawNanAnnotation
User-changeable settings.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTexturedActor2D * TextureActor
Actor for TexturePolyData.