VTK  9.7.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 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
54 
55 VTK_ABI_NAMESPACE_BEGIN
56 class vtkColor3ub;
58 class vtkPolyData;
60 class vtkProperty2D;
62 class vtkScalarsToColors;
63 class vtkTextActor;
64 class vtkTextMapper;
65 class vtkTextProperty;
66 class vtkTexture;
67 class vtkTexturedActor2D;
68 
69 #define VTK_ORIENT_HORIZONTAL 0
70 #define VTK_ORIENT_VERTICAL 1
71 
72 class VTKRENDERINGANNOTATION_EXPORT VTK_MARSHALAUTO vtkScalarBarActor : public vtkActor2D
73 {
74 public:
75  vtkTypeMacro(vtkScalarBarActor, vtkActor2D);
76  void PrintSelf(ostream& os, vtkIndent indent) override;
77 
83  static vtkScalarBarActor* New();
84 
86 
89  int RenderOpaqueGeometry(vtkViewport* viewport) override;
90  int RenderTranslucentPolygonalGeometry(vtkViewport*) override { return 0; }
91  int RenderOverlay(vtkViewport* viewport) override;
93 
98 
104  void ReleaseGraphicsResources(vtkWindow*) override;
105 
111  virtual void GetScalarBarRect(int rect[4], vtkViewport* viewport);
112 
114 
120  virtual void SetLookupTable(vtkScalarsToColors*);
121  vtkGetObjectMacro(LookupTable, vtkScalarsToColors);
123 
125 
132  virtual void SetOpacityFunction(vtkPiecewiseFunction*);
133  vtkGetObjectMacro(OpacityFunction, vtkPiecewiseFunction);
135 
137 
149  vtkSetMacro(UseOpacity, vtkTypeBool);
150  vtkGetMacro(UseOpacity, vtkTypeBool);
151  vtkBooleanMacro(UseOpacity, vtkTypeBool);
153 
155 
160  vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_INT_MAX);
161  vtkGetMacro(MaximumNumberOfColors, int);
163 
165 
168  vtkSetClampMacro(NumberOfLabels, int, 0, 64);
169  vtkGetMacro(NumberOfLabels, int);
171 
173 
176  virtual void SetCustomLabels(vtkDoubleArray* labels);
177  vtkGetObjectMacro(CustomLabels, vtkDoubleArray);
179 
181 
185  vtkGetMacro(UseCustomLabels, bool);
186  vtkSetMacro(UseCustomLabels, bool);
187  vtkBooleanMacro(UseCustomLabels, bool);
189 
191 
194  vtkSetClampMacro(Orientation, int, VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
195  vtkGetMacro(Orientation, int);
196  void SetOrientationToHorizontal() { this->SetOrientation(VTK_ORIENT_HORIZONTAL); }
197  void SetOrientationToVertical() { this->SetOrientation(VTK_ORIENT_VERTICAL); }
199 
201 
204  vtkGetMacro(ForceVerticalTitle, bool);
205  vtkSetMacro(ForceVerticalTitle, bool);
207 
209 
212  virtual void SetTitleTextProperty(vtkTextProperty* p);
213  vtkGetObjectMacro(TitleTextProperty, vtkTextProperty);
215 
217 
220  virtual void SetLabelTextProperty(vtkTextProperty* p);
221  vtkGetObjectMacro(LabelTextProperty, vtkTextProperty);
223 
225 
228  virtual void SetAnnotationTextProperty(vtkTextProperty* p);
229  vtkGetObjectMacro(AnnotationTextProperty, vtkTextProperty);
231 
233 
237  vtkSetStringMacro(LabelFormat);
238  vtkGetStringMacro(LabelFormat);
240 
242 
245  vtkSetStringMacro(Title);
246  vtkGetStringMacro(Title);
248 
250 
253  vtkSetStringMacro(ComponentTitle);
254  vtkGetStringMacro(ComponentTitle);
256 
260  void ShallowCopy(vtkProp* prop) override;
261 
263 
266  vtkSetMacro(TextureGridWidth, double);
267  vtkGetMacro(TextureGridWidth, double);
269 
271 
274  vtkGetObjectMacro(TextureActor, vtkTexturedActor2D);
276 
277  enum
278  {
279  PrecedeScalarBar = 0,
280  SucceedScalarBar
281  };
282 
284 
292  vtkSetClampMacro(TextPosition, int, PrecedeScalarBar, SucceedScalarBar);
293  vtkGetMacro(TextPosition, int);
295  {
296  this->SetTextPosition(vtkScalarBarActor::PrecedeScalarBar);
297  }
299  {
300  this->SetTextPosition(vtkScalarBarActor::SucceedScalarBar);
301  }
303 
305 
312  vtkSetMacro(MaximumWidthInPixels, int);
313  vtkGetMacro(MaximumWidthInPixels, int);
314  vtkSetMacro(MaximumHeightInPixels, int);
315  vtkGetMacro(MaximumHeightInPixels, int);
317 
319 
324  vtkSetMacro(AnnotationLeaderPadding, double);
325  vtkGetMacro(AnnotationLeaderPadding, double);
327 
329 
334  vtkSetMacro(DrawAnnotations, vtkTypeBool);
335  vtkGetMacro(DrawAnnotations, vtkTypeBool);
336  vtkBooleanMacro(DrawAnnotations, vtkTypeBool);
338 
340 
345  vtkSetMacro(DrawNanAnnotation, vtkTypeBool);
346  vtkGetMacro(DrawNanAnnotation, vtkTypeBool);
347  vtkBooleanMacro(DrawNanAnnotation, vtkTypeBool);
349 
351 
356  vtkSetMacro(DrawBelowRangeSwatch, bool);
357  vtkGetMacro(DrawBelowRangeSwatch, bool);
358  vtkBooleanMacro(DrawBelowRangeSwatch, bool);
360 
362 
365  vtkSetStringMacro(BelowRangeAnnotation);
366  vtkGetStringMacro(BelowRangeAnnotation);
368 
370 
375  vtkSetMacro(DrawAboveRangeSwatch, bool);
376  vtkGetMacro(DrawAboveRangeSwatch, bool);
377  vtkBooleanMacro(DrawAboveRangeSwatch, bool);
379 
381 
384  vtkSetStringMacro(AboveRangeAnnotation);
385  vtkGetStringMacro(AboveRangeAnnotation);
388 
396  vtkSetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
397  vtkGetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
398  vtkBooleanMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
400 
402 
405  vtkSetStringMacro(NanAnnotation);
406  vtkGetStringMacro(NanAnnotation);
408 
410 
418  vtkSetMacro(AnnotationTextScaling, vtkTypeBool);
419  vtkGetMacro(AnnotationTextScaling, vtkTypeBool);
420  vtkBooleanMacro(AnnotationTextScaling, vtkTypeBool);
422 
424 
428  vtkSetMacro(DrawBackground, vtkTypeBool);
429  vtkGetMacro(DrawBackground, vtkTypeBool);
430  vtkBooleanMacro(DrawBackground, vtkTypeBool);
432 
434 
438  vtkSetMacro(DrawFrame, vtkTypeBool);
439  vtkGetMacro(DrawFrame, vtkTypeBool);
440  vtkBooleanMacro(DrawFrame, vtkTypeBool);
442 
444 
448  vtkSetMacro(DrawColorBar, vtkTypeBool);
449  vtkGetMacro(DrawColorBar, vtkTypeBool);
450  vtkBooleanMacro(DrawColorBar, vtkTypeBool);
452 
454 
457  vtkSetMacro(DrawTickLabels, vtkTypeBool);
458  vtkGetMacro(DrawTickLabels, vtkTypeBool);
459  vtkBooleanMacro(DrawTickLabels, vtkTypeBool);
461 
463 
466  virtual void SetBackgroundProperty(vtkProperty2D* p);
467  vtkGetObjectMacro(BackgroundProperty, vtkProperty2D);
469 
471 
474  virtual void SetFrameProperty(vtkProperty2D* p);
475  vtkGetObjectMacro(FrameProperty, vtkProperty2D);
477 
479 
483  vtkGetMacro(TextPad, int);
484  vtkSetMacro(TextPad, int);
486 
488 
492  vtkGetMacro(VerticalTitleSeparation, int);
493  vtkSetMacro(VerticalTitleSeparation, int);
495 
497 
501  vtkGetMacro(BarRatio, double);
502  vtkSetClampMacro(BarRatio, double, 0., 1.);
504 
506 
512  vtkGetMacro(TitleRatio, double);
513  vtkSetClampMacro(TitleRatio, double, 0., 1.);
515 
517 
523  vtkSetMacro(UnconstrainedFontSize, bool);
524  vtkGetMacro(UnconstrainedFontSize, bool);
525  vtkBooleanMacro(UnconstrainedFontSize, bool);
527 
532  void SetPositionCoordinate(vtkCoordinate* pos) override;
533 
534 protected:
536  ~vtkScalarBarActor() override;
537 
562  virtual void RebuildLayout(vtkViewport* viewport);
563 
569  virtual int RebuildLayoutIfNeeded(vtkViewport* viewport);
570 
574  virtual void FreeLayoutStorage();
575 
584  virtual void ComputeFrame();
585 
595  virtual void ComputeScalarBarThickness();
596 
600  virtual void ComputeSwatchPad();
601 
602  // This method must set this->P->NanSwatchSize and this->P->NanBox.
603  // It may depend on layout performed by ComputeScalarBarThickness.
604  virtual void LayoutNanSwatch();
605 
612  virtual void LayoutBelowRangeSwatch();
613 
620  virtual void LayoutAboveRangeSwatch();
621 
628  virtual void LayoutAboveRangeSwatchPosn();
629 
633  virtual void PrepareTitleText();
634 
645  virtual void LayoutTitle();
646 
651  virtual void LayoutForUnconstrainedFont();
652 
661  virtual void ComputeScalarBarLength();
662 
674  virtual void LayoutTicks();
675 
683  virtual void LayoutAnnotations();
684 
688  virtual void ConfigureAnnotations();
689 
693  virtual void ConfigureFrame();
694 
698  virtual void DrawBoxes();
699 
703  virtual void ConfigureScalarBar();
704 
708  virtual void ConfigureTitle();
709 
713  virtual void ConfigureTicks();
714 
721  virtual void ConfigureNanSwatch();
722 
727  virtual void ConfigureAboveBelowRangeSwatch(bool above);
728 
737  virtual void EditAnnotations() {}
738 
744  virtual void SizeTitle(double* titleSize, int* size, vtkViewport* viewport);
745 
749  int MapAnnotationLabels(
750  vtkScalarsToColors* lkup, double start, double delta, const double* range);
751 
755  int PlaceAnnotationsVertically(
756  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
761  int PlaceAnnotationsHorizontally(
762  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
763 
770  vtkDoubleArray* CustomLabels = nullptr;
771  bool UseCustomLabels = false;
772  vtkTypeBool DrawBackground; // off by default
773  vtkTypeBool DrawFrame; // off by default
774  vtkTypeBool DrawColorBar; // on by default
775  vtkTypeBool DrawTickLabels; // on by default
782  char* Title;
784  char* LabelFormat;
785  vtkTypeBool UseOpacity; // off by default
794  int TextPad;
796  double BarRatio;
797  double TitleRatio;
798  bool UnconstrainedFontSize; // off by default
799  bool ForceVerticalTitle; // off by default
800 
804 
808  int LastSize[2];
809  int LastOrigin[2];
810 
812 
815 
820 
827 
831 
835 
837 private:
838  vtkScalarBarActor(const vtkScalarBarActor&) = delete;
839  void operator=(const vtkScalarBarActor&) = delete;
840 };
841 
842 VTK_ABI_NAMESPACE_END
843 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:49
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.
Defines a 1D piecewise function.
abstract specification for Viewports
Definition: vtkViewport.h:46
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:192
vtkPolyDataMapper2D * BackgroundMapper
Mapper for Background.
a actor that draws 2D data
Definition: vtkActor2D.h:35
record modification and/or execution time
Definition: vtkTimeStamp.h:24
Internal state for the scalar bar actor shared with subclasses.
virtual void SetPositionCoordinate(vtkCoordinate *)
Get the PositionCoordinate instance of vtkCoordinate.
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:71
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:41
vtkActor2D * BackgroundActor
Actor for Background.
An actor that displays text.
Definition: vtkTextActor.h:48
#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:58
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.
vtkPiecewiseFunction * OpacityFunction
The opacity function if UseOpacity is true.
represent text properties.
vtkPolyData * Background
Polygon used to fill the background.
vtkTextProperty * LabelTextProperty
Font for tick labels.
vtkTimeStamp BuildTime
Internal state used for rendering.
perform coordinate transformation, and represent position, in a variety of vtk coordinate systems ...
Definition: vtkCoordinate.h:69
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.
bool ForceVerticalTitle
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:30
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.
#define VTK_MARSHALAUTO
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.