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 =========================================================================*/
59 #ifndef vtkScalarBarActor_h
60 #define vtkScalarBarActor_h
61 
62 #include "vtkActor2D.h"
63 #include "vtkDoubleArray.h" // for ivars
64 #include "vtkRenderingAnnotationModule.h" // For export macro
65 
66 class vtkColor3ub;
67 class vtkPolyData;
69 class vtkProperty2D;
70 class vtkScalarsToColors;
72 class vtkTextActor;
73 class vtkTextMapper;
74 class vtkTextProperty;
75 class vtkTexture;
76 class vtkTexturedActor2D;
77 
78 #define VTK_ORIENT_HORIZONTAL 0
79 #define VTK_ORIENT_VERTICAL 1
80 
81 class VTKRENDERINGANNOTATION_EXPORT vtkScalarBarActor : public vtkActor2D
82 {
83 public:
84  vtkTypeMacro(vtkScalarBarActor, vtkActor2D);
85  void PrintSelf(ostream& os, vtkIndent indent) override;
86 
92  static vtkScalarBarActor* New();
93 
95 
98  int RenderOpaqueGeometry(vtkViewport* viewport) override;
99  int RenderTranslucentPolygonalGeometry(vtkViewport*) override { return 0; }
100  int RenderOverlay(vtkViewport* viewport) override;
102 
107 
113  void ReleaseGraphicsResources(vtkWindow*) override;
114 
120  virtual void GetScalarBarRect(int rect[4], vtkViewport* viewport);
121 
123 
129  virtual void SetLookupTable(vtkScalarsToColors*);
130  vtkGetObjectMacro(LookupTable, vtkScalarsToColors);
132 
134 
141  vtkSetMacro(UseOpacity, vtkTypeBool);
142  vtkGetMacro(UseOpacity, vtkTypeBool);
143  vtkBooleanMacro(UseOpacity, vtkTypeBool);
145 
147 
152  vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_INT_MAX);
153  vtkGetMacro(MaximumNumberOfColors, int);
155 
157 
160  vtkSetClampMacro(NumberOfLabels, int, 0, 64);
161  vtkGetMacro(NumberOfLabels, int);
163 
165 
168  virtual void SetCustomLabels(vtkDoubleArray* labels);
169  vtkGetObjectMacro(CustomLabels, vtkDoubleArray);
171 
173 
177  vtkGetMacro(UseCustomLabels, bool);
178  vtkSetMacro(UseCustomLabels, bool);
179  vtkBooleanMacro(UseCustomLabels, bool);
181 
183 
186  vtkSetClampMacro(Orientation, int, VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
187  vtkGetMacro(Orientation, int);
188  void SetOrientationToHorizontal() { this->SetOrientation(VTK_ORIENT_HORIZONTAL); }
189  void SetOrientationToVertical() { this->SetOrientation(VTK_ORIENT_VERTICAL); }
191 
193 
196  virtual void SetTitleTextProperty(vtkTextProperty* p);
197  vtkGetObjectMacro(TitleTextProperty, vtkTextProperty);
199 
201 
204  virtual void SetLabelTextProperty(vtkTextProperty* p);
205  vtkGetObjectMacro(LabelTextProperty, vtkTextProperty);
207 
209 
212  virtual void SetAnnotationTextProperty(vtkTextProperty* p);
213  vtkGetObjectMacro(AnnotationTextProperty, vtkTextProperty);
215 
217 
221  vtkSetStringMacro(LabelFormat);
222  vtkGetStringMacro(LabelFormat);
224 
226 
229  vtkSetStringMacro(Title);
230  vtkGetStringMacro(Title);
232 
234 
237  vtkSetStringMacro(ComponentTitle);
238  vtkGetStringMacro(ComponentTitle);
240 
244  void ShallowCopy(vtkProp* prop) override;
245 
247 
250  vtkSetMacro(TextureGridWidth, double);
251  vtkGetMacro(TextureGridWidth, double);
253 
255 
258  vtkGetObjectMacro(TextureActor, vtkTexturedActor2D);
260 
261  enum
262  {
263  PrecedeScalarBar = 0,
264  SucceedScalarBar
265  };
266 
268 
276  vtkSetClampMacro(TextPosition, int, PrecedeScalarBar, SucceedScalarBar);
277  vtkGetMacro(TextPosition, int);
279  {
280  this->SetTextPosition(vtkScalarBarActor::PrecedeScalarBar);
281  }
283  {
284  this->SetTextPosition(vtkScalarBarActor::SucceedScalarBar);
285  }
287 
289 
296  vtkSetMacro(MaximumWidthInPixels, int);
297  vtkGetMacro(MaximumWidthInPixels, int);
298  vtkSetMacro(MaximumHeightInPixels, int);
299  vtkGetMacro(MaximumHeightInPixels, int);
301 
303 
308  vtkSetMacro(AnnotationLeaderPadding, double);
309  vtkGetMacro(AnnotationLeaderPadding, double);
311 
313 
318  vtkSetMacro(DrawAnnotations, vtkTypeBool);
319  vtkGetMacro(DrawAnnotations, vtkTypeBool);
320  vtkBooleanMacro(DrawAnnotations, vtkTypeBool);
322 
324 
329  vtkSetMacro(DrawNanAnnotation, vtkTypeBool);
330  vtkGetMacro(DrawNanAnnotation, vtkTypeBool);
331  vtkBooleanMacro(DrawNanAnnotation, vtkTypeBool);
333 
335 
340  vtkSetMacro(DrawBelowRangeSwatch, bool);
341  vtkGetMacro(DrawBelowRangeSwatch, bool);
342  vtkBooleanMacro(DrawBelowRangeSwatch, bool);
344 
346 
349  vtkSetStringMacro(BelowRangeAnnotation);
350  vtkGetStringMacro(BelowRangeAnnotation);
352 
354 
359  vtkSetMacro(DrawAboveRangeSwatch, bool);
360  vtkGetMacro(DrawAboveRangeSwatch, bool);
361  vtkBooleanMacro(DrawAboveRangeSwatch, bool);
363 
365 
368  vtkSetStringMacro(AboveRangeAnnotation);
369  vtkGetStringMacro(AboveRangeAnnotation);
372 
380  vtkSetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
381  vtkGetMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
382  vtkBooleanMacro(FixedAnnotationLeaderLineColor, vtkTypeBool);
384 
386 
389  vtkSetStringMacro(NanAnnotation);
390  vtkGetStringMacro(NanAnnotation);
392 
394 
402  vtkSetMacro(AnnotationTextScaling, vtkTypeBool);
403  vtkGetMacro(AnnotationTextScaling, vtkTypeBool);
404  vtkBooleanMacro(AnnotationTextScaling, vtkTypeBool);
406 
408 
412  vtkSetMacro(DrawBackground, vtkTypeBool);
413  vtkGetMacro(DrawBackground, vtkTypeBool);
414  vtkBooleanMacro(DrawBackground, vtkTypeBool);
416 
418 
422  vtkSetMacro(DrawFrame, vtkTypeBool);
423  vtkGetMacro(DrawFrame, vtkTypeBool);
424  vtkBooleanMacro(DrawFrame, vtkTypeBool);
426 
428 
432  vtkSetMacro(DrawColorBar, vtkTypeBool);
433  vtkGetMacro(DrawColorBar, vtkTypeBool);
434  vtkBooleanMacro(DrawColorBar, vtkTypeBool);
436 
438 
441  vtkSetMacro(DrawTickLabels, vtkTypeBool);
442  vtkGetMacro(DrawTickLabels, vtkTypeBool);
443  vtkBooleanMacro(DrawTickLabels, vtkTypeBool);
445 
447 
450  virtual void SetBackgroundProperty(vtkProperty2D* p);
451  vtkGetObjectMacro(BackgroundProperty, vtkProperty2D);
453 
455 
458  virtual void SetFrameProperty(vtkProperty2D* p);
459  vtkGetObjectMacro(FrameProperty, vtkProperty2D);
461 
463 
467  vtkGetMacro(TextPad, int);
468  vtkSetMacro(TextPad, int);
470 
472 
477  vtkGetMacro(VerticalTitleSeparation, int);
478  vtkSetMacro(VerticalTitleSeparation, int);
480 
482 
486  vtkGetMacro(BarRatio, double);
487  vtkSetClampMacro(BarRatio, double, 0., 1.);
489 
491 
497  vtkGetMacro(TitleRatio, double);
498  vtkSetClampMacro(TitleRatio, double, 0., 1.);
500 
502 
508  vtkSetMacro(UnconstrainedFontSize, bool);
509  vtkGetMacro(UnconstrainedFontSize, bool);
510  vtkBooleanMacro(UnconstrainedFontSize, bool);
512 
513 protected:
515  ~vtkScalarBarActor() override;
516 
541  virtual void RebuildLayout(vtkViewport* viewport);
542 
548  virtual int RebuildLayoutIfNeeded(vtkViewport* viewport);
549 
553  virtual void FreeLayoutStorage();
554 
563  virtual void ComputeFrame();
564 
574  virtual void ComputeScalarBarThickness();
575 
579  virtual void ComputeSwatchPad();
580 
581  // This method must set this->P->NanSwatchSize and this->P->NanBox.
582  // It may depend on layout performed by ComputeScalarBarThickness.
583  virtual void LayoutNanSwatch();
584 
591  virtual void LayoutBelowRangeSwatch();
592 
599  virtual void LayoutAboveRangeSwatch();
600 
607  virtual void LayoutAboveRangeSwatchPosn();
608 
612  virtual void PrepareTitleText();
613 
624  virtual void LayoutTitle();
625 
630  virtual void LayoutForUnconstrainedFont();
631 
640  virtual void ComputeScalarBarLength();
641 
653  virtual void LayoutTicks();
654 
662  virtual void LayoutAnnotations();
663 
667  virtual void ConfigureAnnotations();
668 
672  virtual void ConfigureFrame();
673 
677  virtual void DrawBoxes();
678 
682  virtual void ConfigureScalarBar();
683 
687  virtual void ConfigureTitle();
688 
692  virtual void ConfigureTicks();
693 
700  virtual void ConfigureNanSwatch();
701 
706  virtual void ConfigureAboveBelowRangeSwatch(bool above);
707 
716  virtual void EditAnnotations() {}
717 
723  virtual void SizeTitle(double* titleSize, int* size, vtkViewport* viewport);
724 
728  int MapAnnotationLabels(
729  vtkScalarsToColors* lkup, double start, double delta, const double* range);
730 
734  int PlaceAnnotationsVertically(
735  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
740  int PlaceAnnotationsHorizontally(
741  double barX, double barY, double barWidth, double barHeight, double delta, double pad);
742 
749  vtkDoubleArray* CustomLabels = nullptr;
750  bool UseCustomLabels = false;
751  vtkTypeBool DrawBackground; // off by default
752  vtkTypeBool DrawFrame; // off by default
753  vtkTypeBool DrawColorBar; // on by default
754  vtkTypeBool DrawTickLabels; // on by default
761  char* Title;
763  char* LabelFormat;
764  vtkTypeBool UseOpacity; // off by default
773  int TextPad;
775  double BarRatio;
776  double TitleRatio;
777  bool UnconstrainedFontSize; // off by default
778 
782 
786  int LastSize[2];
787  int LastOrigin[2];
788 
790 
792 
797 
804 
808 
812 
814 private:
815  vtkScalarBarActor(const vtkScalarBarActor&) = delete;
816  void operator=(const vtkScalarBarActor&) = delete;
817 };
818 
819 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:56
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:55
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:155
vtkPolyDataMapper2D * BackgroundMapper
Mapper for Background.
a actor that draws 2D data
Definition: vtkActor2D.h:45
record modification and/or execution time
Definition: vtkTimeStamp.h:35
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:90
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:50
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:69
char * Title
User-changeable settings.
Superclass for mapping scalar values to colors.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
vtkActor2D * BackgroundActor
Actor for Background.
An actor that displays text.
Definition: vtkTextActor.h:56
#define VTK_ORIENT_HORIZONTAL
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:194
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:39
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:68
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:40
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.