VTK  9.2.6
vtkScalarBarActor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkScalarBarActor.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
68 #ifndef vtkScalarBarActor_h
69 #define vtkScalarBarActor_h
70 
71 #include "vtkActor2D.h"
72 #include "vtkDoubleArray.h" // for ivars
73 #include "vtkRenderingAnnotationModule.h" // For export macro
74 
75 class vtkColor3ub;
76 class vtkPolyData;
78 class vtkProperty2D;
79 class vtkScalarsToColors;
81 class vtkTextActor;
82 class vtkTextMapper;
83 class vtkTextProperty;
84 class vtkTexture;
85 class vtkTexturedActor2D;
86 
87 #define VTK_ORIENT_HORIZONTAL 0
88 #define VTK_ORIENT_VERTICAL 1
89 
90 class VTKRENDERINGANNOTATION_EXPORT vtkScalarBarActor : public vtkActor2D
91 {
92 public:
93  vtkTypeMacro(vtkScalarBarActor, vtkActor2D);
94  void PrintSelf(ostream& os, vtkIndent indent) override;
95 
102 
104 
107  int RenderOpaqueGeometry(vtkViewport* viewport) override;
108  int RenderTranslucentPolygonalGeometry(vtkViewport*) override { return 0; }
109  int RenderOverlay(vtkViewport* viewport) override;
111 
116 
123 
129  virtual void GetScalarBarRect(int rect[4], vtkViewport* viewport);
130 
132 
139  vtkGetObjectMacro(LookupTable, vtkScalarsToColors);
141 
143 
150  vtkSetMacro(UseOpacity, vtkTypeBool);
151  vtkGetMacro(UseOpacity, vtkTypeBool);
152  vtkBooleanMacro(UseOpacity, vtkTypeBool);
154 
156 
161  vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_INT_MAX);
162  vtkGetMacro(MaximumNumberOfColors, int);
164 
166 
169  vtkSetClampMacro(NumberOfLabels, int, 0, 64);
170  vtkGetMacro(NumberOfLabels, int);
172 
174 
177  virtual void SetCustomLabels(vtkDoubleArray* labels);
178  vtkGetObjectMacro(CustomLabels, vtkDoubleArray);
180 
182 
186  vtkGetMacro(UseCustomLabels, bool);
187  vtkSetMacro(UseCustomLabels, bool);
188  vtkBooleanMacro(UseCustomLabels, bool);
190 
192 
195  vtkSetClampMacro(Orientation, int, VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
196  vtkGetMacro(Orientation, int);
197  void SetOrientationToHorizontal() { this->SetOrientation(VTK_ORIENT_HORIZONTAL); }
198  void SetOrientationToVertical() { this->SetOrientation(VTK_ORIENT_VERTICAL); }
200 
202 
206  vtkGetObjectMacro(TitleTextProperty, vtkTextProperty);
208 
210 
214  vtkGetObjectMacro(LabelTextProperty, vtkTextProperty);
216 
218 
222  vtkGetObjectMacro(AnnotationTextProperty, vtkTextProperty);
224 
226 
230  vtkSetStringMacro(LabelFormat);
231  vtkGetStringMacro(LabelFormat);
233 
235 
238  vtkSetStringMacro(Title);
239  vtkGetStringMacro(Title);
241 
243 
246  vtkSetStringMacro(ComponentTitle);
247  vtkGetStringMacro(ComponentTitle);
249 
253  void ShallowCopy(vtkProp* prop) override;
254 
256 
259  vtkSetMacro(TextureGridWidth, double);
260  vtkGetMacro(TextureGridWidth, double);
262 
264 
267  vtkGetObjectMacro(TextureActor, vtkTexturedActor2D);
269 
270  enum
271  {
272  PrecedeScalarBar = 0,
273  SucceedScalarBar
274  };
275 
277 
285  vtkSetClampMacro(TextPosition, int, PrecedeScalarBar, SucceedScalarBar);
286  vtkGetMacro(TextPosition, int);
288  {
289  this->SetTextPosition(vtkScalarBarActor::PrecedeScalarBar);
290  }
292  {
293  this->SetTextPosition(vtkScalarBarActor::SucceedScalarBar);
294  }
296 
298 
305  vtkSetMacro(MaximumWidthInPixels, int);
306  vtkGetMacro(MaximumWidthInPixels, int);
307  vtkSetMacro(MaximumHeightInPixels, int);
308  vtkGetMacro(MaximumHeightInPixels, int);
310 
312 
317  vtkSetMacro(AnnotationLeaderPadding, double);
318  vtkGetMacro(AnnotationLeaderPadding, double);
320 
322 
327  vtkSetMacro(DrawAnnotations, vtkTypeBool);
328  vtkGetMacro(DrawAnnotations, vtkTypeBool);
329  vtkBooleanMacro(DrawAnnotations, vtkTypeBool);
331 
333 
338  vtkSetMacro(DrawNanAnnotation, vtkTypeBool);
339  vtkGetMacro(DrawNanAnnotation, vtkTypeBool);
340  vtkBooleanMacro(DrawNanAnnotation, vtkTypeBool);
342 
344 
349  vtkSetMacro(DrawBelowRangeSwatch, bool);
350  vtkGetMacro(DrawBelowRangeSwatch, bool);
351  vtkBooleanMacro(DrawBelowRangeSwatch, bool);
353 
355 
358  vtkSetStringMacro(BelowRangeAnnotation);
359  vtkGetStringMacro(BelowRangeAnnotation);
361 
363 
368  vtkSetMacro(DrawAboveRangeSwatch, bool);
369  vtkGetMacro(DrawAboveRangeSwatch, bool);
370  vtkBooleanMacro(DrawAboveRangeSwatch, bool);
372 
374 
377  vtkSetStringMacro(AboveRangeAnnotation);
378  vtkGetStringMacro(AboveRangeAnnotation);
381 
389  vtkSetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
390  vtkGetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
391  vtkBooleanMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
393 
395 
398  vtkSetStringMacro(NanAnnotation);
399  vtkGetStringMacro(NanAnnotation);
401 
403 
411  vtkSetMacro(AnnotationTextScaling, vtkTypeBool);
412  vtkGetMacro(AnnotationTextScaling, vtkTypeBool);
413  vtkBooleanMacro(AnnotationTextScaling, vtkTypeBool);
415 
417 
421  vtkSetMacro(DrawBackground, vtkTypeBool);
422  vtkGetMacro(DrawBackground, vtkTypeBool);
423  vtkBooleanMacro(DrawBackground, vtkTypeBool);
425 
427 
431  vtkSetMacro(DrawFrame, vtkTypeBool);
432  vtkGetMacro(DrawFrame, vtkTypeBool);
433  vtkBooleanMacro(DrawFrame, vtkTypeBool);
435 
437 
441  vtkSetMacro(DrawColorBar, vtkTypeBool);
442  vtkGetMacro(DrawColorBar, vtkTypeBool);
443  vtkBooleanMacro(DrawColorBar, vtkTypeBool);
445 
447 
450  vtkSetMacro(DrawTickLabels, vtkTypeBool);
451  vtkGetMacro(DrawTickLabels, vtkTypeBool);
452  vtkBooleanMacro(DrawTickLabels, vtkTypeBool);
454 
456 
460  vtkGetObjectMacro(BackgroundProperty, vtkProperty2D);
462 
464 
467  virtual void SetFrameProperty(vtkProperty2D* p);
468  vtkGetObjectMacro(FrameProperty, vtkProperty2D);
470 
472 
476  vtkGetMacro(TextPad, int);
477  vtkSetMacro(TextPad, int);
479 
481 
486  vtkGetMacro(VerticalTitleSeparation, int);
487  vtkSetMacro(VerticalTitleSeparation, int);
489 
491 
495  vtkGetMacro(BarRatio, double);
496  vtkSetClampMacro(BarRatio, double, 0., 1.);
498 
500 
506  vtkGetMacro(TitleRatio, double);
507  vtkSetClampMacro(TitleRatio, double, 0., 1.);
509 
511 
517  vtkSetMacro(UnconstrainedFontSize, bool);
518  vtkGetMacro(UnconstrainedFontSize, bool);
519  vtkBooleanMacro(UnconstrainedFontSize, bool);
521 
522 protected:
524  ~vtkScalarBarActor() override;
525 
550  virtual void RebuildLayout(vtkViewport* viewport);
551 
557  virtual int RebuildLayoutIfNeeded(vtkViewport* viewport);
558 
562  virtual void FreeLayoutStorage();
563 
572  virtual void ComputeFrame();
573 
584 
588  virtual void ComputeSwatchPad();
589 
590  // This method must set this->P->NanSwatchSize and this->P->NanBox.
591  // It may depend on layout performed by ComputeScalarBarThickness.
592  virtual void LayoutNanSwatch();
593 
600  virtual void LayoutBelowRangeSwatch();
601 
608  virtual void LayoutAboveRangeSwatch();
609 
617 
621  virtual void PrepareTitleText();
622 
633  virtual void LayoutTitle();
634 
640 
649  virtual void ComputeScalarBarLength();
650 
662  virtual void LayoutTicks();
663 
671  virtual void LayoutAnnotations();
672 
676  virtual void ConfigureAnnotations();
677 
681  virtual void ConfigureFrame();
682 
686  virtual void DrawBoxes();
687 
691  virtual void ConfigureScalarBar();
692 
696  virtual void ConfigureTitle();
697 
701  virtual void ConfigureTicks();
702 
709  virtual void ConfigureNanSwatch();
710 
715  virtual void ConfigureAboveBelowRangeSwatch(bool above);
716 
725  virtual void EditAnnotations() {}
726 
732  virtual void SizeTitle(double* titleSize, int* size, vtkViewport* viewport);
733 
738  vtkScalarsToColors* lkup, double start, double delta, const double* range);
739 
744  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
750  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
751 
758  vtkDoubleArray* CustomLabels = nullptr;
759  bool UseCustomLabels = false;
760  vtkTypeBool DrawBackground; // off by default
761  vtkTypeBool DrawFrame; // off by default
762  vtkTypeBool DrawColorBar; // on by default
763  vtkTypeBool DrawTickLabels; // on by default
770  char* Title;
772  char* LabelFormat;
773  vtkTypeBool UseOpacity; // off by default
782  int TextPad;
784  double BarRatio;
785  double TitleRatio;
786  bool UnconstrainedFontSize; // off by default
787 
791 
795  int LastSize[2];
796  int LastOrigin[2];
797 
799 
801 
806 
813 
817 
822 
823 private:
824  vtkScalarBarActor(const vtkScalarBarActor&) = delete;
825  void operator=(const vtkScalarBarActor&) = delete;
826 };
827 
828 #endif
a actor that draws 2D data
Definition: vtkActor2D.h:55
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:204
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition: vtkIndent.h:49
draw vtkPolyData onto the image plane
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:100
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:66
represent surface properties of a 2D image
Definition: vtkProperty2D.h:50
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:66
2D text annotation
Definition: vtkTextMapper.h:60
represent text properties.
handles properties associated with a texture map
Definition: vtkTexture.h:78
actor that draws 2D data with texture support
record modification and/or execution time
Definition: vtkTimeStamp.h:45
abstract specification for Viewports
Definition: vtkViewport.h:65
window superclass for vtkRenderWindow
Definition: vtkWindow.h:48
@ range
Definition: vtkX3D.h:244
@ size
Definition: vtkX3D.h:259
int vtkTypeBool
Definition: vtkABI.h:69
#define VTK_ORIENT_VERTICAL
#define VTK_ORIENT_HORIZONTAL
#define VTK_INT_MAX
Definition: vtkType.h:155