Commit ffd7a24f authored by Mathieu Westphal's avatar Mathieu Westphal Committed by Kitware Robot
Browse files

Merge topic 'ScalarBarFeatures'

abf59cdb

 Scalar bar features
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: David Thompson's avatarDavid Thompson <david.thompson@kitware.com>
Acked-by: default avatarJoachim Pouderoux <joachim.pouderoux@kitware.com>
Reviewed-by: Cory Quammen's avatarCory Quammen <cory.quammen@kitware.com>
Merge-request: !1220
parents 699a706c abf59cdb
Pipeline #7774 failed with stage
......@@ -100,6 +100,7 @@ int TestGL2PSScalarBar( int argc, char *argv[] )
scalarBar1->SetTextPositionToPrecedeScalarBar();
scalarBar1->GetTitleTextProperty()->SetColor( 0., 0., 1. );
scalarBar1->GetLabelTextProperty()->SetColor( 0., 0., 1. );
scalarBar1->GetAnnotationTextProperty()->SetColor( 0., 0., 1. );
scalarBar1->SetDrawFrame( 1 );
scalarBar1->GetFrameProperty()->SetColor( 0., 0., 0. );
scalarBar1->SetDrawBackground( 1 );
......
......@@ -22,6 +22,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestPieChartActor.cxx
TestPolarAxes.cxx
TestScalarBar.cxx
TestScalarBarAboveBelow.cxx
TestSpiderPlotActor.cxx
TestCubeAxesOrientedBoundingBox.cxx
TestCubeAxesIntersectionPoint.cxx
......
......@@ -98,6 +98,7 @@ int TestScalarBar( int argc, char *argv[] )
scalarBar1->SetTextPositionToPrecedeScalarBar();
scalarBar1->GetTitleTextProperty()->SetColor( 0., 0., 1. );
scalarBar1->GetLabelTextProperty()->SetColor( 0., 0., 1. );
scalarBar1->GetAnnotationTextProperty()->SetColor( 0., 0., 1. );
scalarBar1->SetDrawFrame( 1 );
scalarBar1->GetFrameProperty()->SetColor( 0., 0., 0. );
scalarBar1->SetDrawBackground( 1 );
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestScalarBarAboveBelow.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkCellData.h"
#include "vtkDoubleArray.h"
#include "vtkLookupTable.h"
#include "vtkNew.h"
#include "vtkPlaneSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkScalarBarActor.h"
int TestScalarBarAboveBelow(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
{
int resolution = 3;
vtkNew<vtkPlaneSource> plane;
plane->SetXResolution(resolution);
plane->SetYResolution(resolution);
vtkNew<vtkDoubleArray> cellData;
for (int i = 0; i < resolution * resolution; i++)
{
cellData->InsertNextValue(i);
}
plane->Update(); // Force an update so we can set cell data
plane->GetOutput()->GetCellData()->SetScalars(cellData.Get());
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(plane->GetOutputPort());
mapper->SetScalarRange(1, 7);
vtkNew<vtkActor> actor;
actor->SetMapper(mapper.Get());
vtkScalarsToColors* stc = mapper->GetLookupTable();
vtkLookupTable* lut = vtkLookupTable::SafeDownCast(stc);
lut->SetUseBelowRangeColor(true);
lut->SetUseAboveRangeColor(true);
lut->SetNumberOfColors(7);
vtkNew<vtkScalarBarActor> scalarBar;
scalarBar->SetLookupTable(stc);
scalarBar->SetDrawBelowRangeSwatch(true);
scalarBar->SetDrawAboveRangeSwatch(true);
vtkNew<vtkScalarBarActor> scalarBar2;
scalarBar2->SetLookupTable(stc);
scalarBar2->SetDrawBelowRangeSwatch(true);
scalarBar2->SetOrientationToHorizontal();
scalarBar2->SetWidth(0.5);
scalarBar2->SetHeight(0.15);
scalarBar2->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
scalarBar2->GetPositionCoordinate()->SetValue(.05, .8);
vtkNew<vtkScalarBarActor> scalarBar3;
scalarBar3->SetLookupTable(stc);
scalarBar3->SetDrawAboveRangeSwatch(true);
scalarBar3->SetOrientationToHorizontal();
scalarBar3->SetWidth(0.5);
scalarBar3->SetHeight(0.15);
scalarBar3->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
scalarBar3->GetPositionCoordinate()->SetValue(.05, .2);
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer.Get());
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow.Get());
renderer->AddActor(actor.Get());
renderer->AddActor(scalarBar.Get());
renderer->AddActor(scalarBar2.Get());
renderer->AddActor(scalarBar3.Get());
renderer->SetBackground(.5, .5, .5);
renderWindow->SetMultiSamples(0);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
243828cd3f3c307e1ce2a652ffe163e7
4026c990e1f710d2b54e7c89515948ee
This diff is collapsed.
......@@ -74,7 +74,7 @@ class vtkTexturedActor2D;
class VTKRENDERINGANNOTATION_EXPORT vtkScalarBarActor : public vtkActor2D
{
public:
vtkTypeMacro(vtkScalarBarActor,vtkActor2D);
vtkTypeMacro(vtkScalarBarActor, vtkActor2D);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
......@@ -111,7 +111,7 @@ public:
// and any annotated values.
// Annotated values are rendered using vtkTextActor.
virtual void SetLookupTable(vtkScalarsToColors*);
vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
vtkGetObjectMacro(LookupTable, vtkScalarsToColors);
// Description:
// Should be display the opacity as well. This is displayed by changing
......@@ -119,9 +119,9 @@ public:
// given color. For clarity, a texture grid is placed in the background
// if Opacity is ON. You might also want to play with SetTextureGridWith
// in that case. [Default: off]
vtkSetMacro( UseOpacity, int );
vtkGetMacro( UseOpacity, int );
vtkBooleanMacro( UseOpacity, int );
vtkSetMacro(UseOpacity, int);
vtkGetMacro(UseOpacity, int);
vtkBooleanMacro(UseOpacity, int);
// Description:
// Set/Get the maximum number of scalar bar segments to show. This may
......@@ -137,7 +137,7 @@ public:
// Description:
// Control the orientation of the scalar bar.
vtkSetClampMacro(Orientation,int,VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
vtkSetClampMacro(Orientation, int, VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
vtkGetMacro(Orientation, int);
void SetOrientationToHorizontal()
{this->SetOrientation(VTK_ORIENT_HORIZONTAL);}
......@@ -146,12 +146,17 @@ public:
// Description:
// Set/Get the title text property.
virtual void SetTitleTextProperty(vtkTextProperty* p);
vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
vtkGetObjectMacro(TitleTextProperty, vtkTextProperty);
// Description:
// Set/Get the labels text property.
virtual void SetLabelTextProperty(vtkTextProperty* p);
vtkGetObjectMacro(LabelTextProperty,vtkTextProperty);
vtkGetObjectMacro(LabelTextProperty, vtkTextProperty);
// Description:
// Set/Get the annotation text property.
virtual void SetAnnotationTextProperty(vtkTextProperty* p);
vtkGetObjectMacro(AnnotationTextProperty, vtkTextProperty);
// Description:
// Set/Get the format with which to print the labels on the scalar
......@@ -175,12 +180,12 @@ public:
// Description:
// Set the width of the texture grid. Used only if UseOpacity is ON.
vtkSetMacro( TextureGridWidth, double );
vtkGetMacro( TextureGridWidth, double );
vtkSetMacro(TextureGridWidth, double);
vtkGetMacro(TextureGridWidth, double);
// Description:
// Get the texture actor.. you may want to change some properties on it
vtkGetObjectMacro( TextureActor, vtkTexturedActor2D );
vtkGetObjectMacro(TextureActor, vtkTexturedActor2D);
//BTX
enum { PrecedeScalarBar = 0, SucceedScalarBar };
......@@ -193,12 +198,12 @@ public:
// Thus, succeed implies the that the text is above scalar bar if
// the orientation is horizontal or right of scalar bar if the orientation
// is vertical. Precede is the opposite.
vtkSetClampMacro( TextPosition, int, PrecedeScalarBar, SucceedScalarBar);
vtkGetMacro( TextPosition, int );
vtkSetClampMacro(TextPosition, int, PrecedeScalarBar, SucceedScalarBar);
vtkGetMacro(TextPosition, int);
virtual void SetTextPositionToPrecedeScalarBar()
{ this->SetTextPosition( vtkScalarBarActor::PrecedeScalarBar ); }
{ this->SetTextPosition(vtkScalarBarActor::PrecedeScalarBar); }
virtual void SetTextPositionToSucceedScalarBar()
{ this->SetTextPosition( vtkScalarBarActor::SucceedScalarBar ); }
{ this->SetTextPosition(vtkScalarBarActor::SucceedScalarBar); }
// Description:
// Set/Get the maximum width and height in pixels. Specifying the size as
......@@ -206,10 +211,10 @@ public:
// the size of the actor too much. These methods allow the user to set
// bounds on the maximum size of the scalar bar in pixels along any
// direction. Defaults to unbounded.
vtkSetMacro( MaximumWidthInPixels, int );
vtkGetMacro( MaximumWidthInPixels, int );
vtkSetMacro( MaximumHeightInPixels, int );
vtkGetMacro( MaximumHeightInPixels, int );
vtkSetMacro(MaximumWidthInPixels, int);
vtkGetMacro(MaximumWidthInPixels, int);
vtkSetMacro(MaximumHeightInPixels, int);
vtkGetMacro(MaximumHeightInPixels, int);
// Description:
// Set/get the padding between the scalar bar and the text annotations.
......@@ -234,6 +239,31 @@ public:
vtkGetMacro(DrawNanAnnotation, int);
vtkBooleanMacro(DrawNanAnnotation, int);
// Description:
// Set/get whether the Below range swatch should be rendered or not.
// This only affects rendering when \a DrawAnnotations is true.
// The default is false.
vtkSetMacro(DrawBelowRangeSwatch, bool);
vtkGetMacro(DrawBelowRangeSwatch, bool);
vtkBooleanMacro(DrawBelowRangeSwatch, bool);
// Description:
// Set/get the annotation text for "Below Range" values.
vtkSetStringMacro(BelowRangeAnnotation);
vtkGetStringMacro(BelowRangeAnnotation);
// Description:
// Set/get whether the Above range swatch should be rendered or not.
// This only affects rendering when \a DrawAnnotations is true.
// The default is false.
vtkSetMacro(DrawAboveRangeSwatch, bool);
vtkGetMacro(DrawAboveRangeSwatch, bool);
vtkBooleanMacro(DrawAboveRangeSwatch, bool);
// Description:
// Set/get the annotation text for "Above Range Swatch" values.
vtkSetStringMacro(AboveRangeAnnotation);
vtkGetStringMacro(AboveRangeAnnotation);
// Description:
// Set/get how leader lines connecting annotations to values should be colored.
//
......@@ -257,8 +287,9 @@ public:
// If non-zero, the vtkTextActor instances used to render annotation
// labels will have their TextScaleMode set to viewport-based scaling,
// which nonlinearly scales font size with the viewport size.
vtkSetMacro(AnnotationTextScaling,int);
vtkGetMacro(AnnotationTextScaling,int);
vtkSetMacro(AnnotationTextScaling, int);
vtkGetMacro(AnnotationTextScaling, int);
vtkBooleanMacro(AnnotationTextScaling, int);
// Description:
// Set/Get whether a background should be drawn around the scalar bar.
......@@ -290,39 +321,47 @@ public:
// Description:
// Set/Get the background property.
virtual void SetBackgroundProperty(vtkProperty2D* p);
vtkGetObjectMacro(BackgroundProperty,vtkProperty2D);
vtkGetObjectMacro(BackgroundProperty, vtkProperty2D);
// Description:
// Set/Get the frame property.
virtual void SetFrameProperty(vtkProperty2D* p);
vtkGetObjectMacro(FrameProperty,vtkProperty2D);
vtkGetObjectMacro(FrameProperty, vtkProperty2D);
// Description:
// Set/get the amount of padding around text boxes.
// The default is 1 pixel.
vtkGetMacro(TextPad,int);
vtkSetMacro(TextPad,int);
vtkGetMacro(TextPad, int);
vtkSetMacro(TextPad, int);
// Description:
// Set/get the margin in pixels, between the title and the bar,
// when the \a Orientation is vertical.
// The default is 0 pixels.
vtkGetMacro(VerticalTitleSeparation,int);
vtkSetMacro(VerticalTitleSeparation,int);
vtkGetMacro(VerticalTitleSeparation, int);
vtkSetMacro(VerticalTitleSeparation, int);
// Description:
// Set/get the thickness of the color bar relative to the widget frame.
// The default is 0.375 and must always be in the range ]0, 1[.
vtkGetMacro(BarRatio,double);
vtkSetClampMacro(BarRatio,double,0.,1.);
vtkGetMacro(BarRatio, double);
vtkSetClampMacro(BarRatio, double, 0., 1.);
// Description:
// Set/get the ratio of the title height to the tick label height
// (used only when the \a Orientation is horizontal).
// The default is 0.5, which attempts to make the labels and title
// the same size. This must be a number in the range ]0, 1[.
vtkGetMacro(TitleRatio,double);
vtkSetClampMacro(TitleRatio,double,0.,1.);
vtkGetMacro(TitleRatio, double);
vtkSetClampMacro(TitleRatio, double, 0., 1.);
// Description:
// Set/Get whether the font size of title and labels is unconstrained. Default is off.
// When it is constrained, the size of the scalar bar will constrained the font size
// When it is not, the size of the font will always be respected
vtkSetMacro(UnconstrainedFontSize, bool);
vtkGetMacro(UnconstrainedFontSize, bool);
vtkBooleanMacro(UnconstrainedFontSize, bool);
protected:
vtkScalarBarActor();
......@@ -377,12 +416,34 @@ protected:
virtual void ComputeScalarBarThickness();
// Description:
// Determine the size of the NaN swatch if it is to be rendered.
//
// Compute a correct SwatchPad
virtual void ComputeSwatchPad();
// This method must set this->P->NanSwatchSize and this->P->NanBox.
// It may depend on layout performed by ComputeScalarBarThickness.
virtual void LayoutNanSwatch();
// Description:
// Determine the size of the Below Range if it is to be rendered.
//
// This method must set this->P->BelowSwatchSize and this->P->BelowBox.
// It may depend on layout performed by ComputeScalarBarThickness.
virtual void LayoutBelowRangeSwatch();
// Description:
// Determine the size of the Above Range if it is to be rendered.
//
// This method must set this->P->AboveBox.
// It may depend on layout performed by ComputeScalarBarThickness.
virtual void LayoutAboveRangeSwatch();
// Description:
// Determine the position of the Above Range if it is to be rendered.
//
// This method must set this->P->AboveRangeSize.
// It may depend on layout performed by ComputeScalarBarLength.
virtual void LayoutAboveRangeSwatchPosn();
// Description:
// Set the title actor's input to the latest title (and subtitle) text.
virtual void PrepareTitleText();
......@@ -398,6 +459,11 @@ protected:
// than the title box.
virtual void LayoutTitle();
// Description:
// This method sets the title and tick-box size and position
// for the UnconstrainedFontSize mode.
virtual void LayoutForUnconstrainedFont();
// Description:
// Determine how long the scalar bar should be (on an axis parallel
// to the direction in which scalar values vary).
......@@ -456,6 +522,11 @@ protected:
// This may change in the future.
virtual void ConfigureNanSwatch();
// Description:
// Generate/configure the above/below range swatch using the laid-out
// geometry.
virtual void ConfigureAboveBelowRangeSwatch(bool above);
// Description:
// Subclasses may override this method to alter this->P->Labels, allowing
// the addition and removal of annotations. The member maps viewport coordinates
......@@ -510,6 +581,8 @@ protected:
double TextureGridWidth;
int TextPosition;
char* NanAnnotation;
char* BelowRangeAnnotation;
char* AboveRangeAnnotation;
double AnnotationLeaderPadding;
int MaximumWidthInPixels;
int MaximumHeightInPixels;
......@@ -517,6 +590,10 @@ protected:
int VerticalTitleSeparation;
double BarRatio;
double TitleRatio;
bool UnconstrainedFontSize; // off by default
bool DrawBelowRangeSwatch;
bool DrawAboveRangeSwatch;
//@}
/// Internal state used for rendering
......@@ -530,7 +607,8 @@ protected:
vtkScalarsToColors* LookupTable; //!< The object this actor illustrates
vtkTextProperty* TitleTextProperty; //!< Font for the legend title.
vtkTextProperty* LabelTextProperty; //!< Font for tick+annotation labels.
vtkTextProperty* LabelTextProperty; //!< Font for tick labels.
vtkTextProperty* AnnotationTextProperty; //!< Font for annotation labels.
vtkTextActor* TitleActor; //!< The legend title text renderer.
vtkPolyData* ScalarBar; //!< Polygon(s) colored by \a LookupTable.
......@@ -554,6 +632,5 @@ private:
void operator=(const vtkScalarBarActor&); // Not implemented.
};
#endif
......@@ -37,7 +37,7 @@ public:
struct vtkScalarBarBox
{
/// The position of the box in viewport (pixel) coordinates.
vtkTuple<int,2> Posn;
vtkTuple<int, 2> Posn;
/**\brief Size of the box, stored as (thickness, length) not (width, height).
*
......@@ -46,7 +46,7 @@ struct vtkScalarBarBox
* Length is a measure of the box size parallel to the long axis of the scalar bar.
* When the scalar bar orientation is horizontal, length measures width.
*/
vtkTuple<int,2> Size;
vtkTuple<int, 2> Size;
};
/// Internal state for the scalar bar actor shared with subclasses.
......@@ -68,6 +68,14 @@ public:
this->NanSwatch = 0;
this->NanSwatchMapper = 0;
this->NanSwatchActor = 0;
this->BelowRangeSwatch = 0;
this->BelowRangeSwatchMapper = 0;
this->BelowRangeSwatchActor = 0;
this->AboveRangeSwatch = 0;
this->AboveRangeSwatchMapper = 0;
this->AboveRangeSwatchActor = 0;
}
// Define types for smart vectors containing various base classes.
......@@ -87,6 +95,12 @@ public:
/// The thickness and length of the (square) NaN swatch.
double NanSwatchSize;
/// The thickness and length of the (square) Below Range swatch.
double BelowRangeSwatchSize;
/// The thickness and length of the (square) Above Range swatch.
double AboveRangeSwatchSize;
/// Space in pixels between swatches when in indexed lookup mode.
double SwatchPad;
......@@ -124,6 +138,12 @@ public:
/// The bounding box of the NaN swatch
vtkScalarBarBox NanBox;
/// The bounding box of the Below Range
vtkScalarBarBox BelowRangeSwatchBox;
/// The bounding box of the Above Range
vtkScalarBarBox AboveRangeSwatchBox;
/// The bounding box of tick mark anchor points (tick labels are not
/// fully contained)
vtkScalarBarBox TickBox;
......@@ -132,11 +152,11 @@ public:
vtkScalarBarBox TitleBox;
/// Map from viewport coordinates to label text of each annotation.
std::map<double,vtkStdString> Labels;
std::map<double, vtkStdString> Labels;
/// Map from viewport coordinates to the leader line color of each
/// annotation.
std::map<double,vtkColor3ub> LabelColors;
std::map<double, vtkColor3ub> LabelColors;
//@}
/// Cache of classes holding geometry assembled and ready for rendering.
......@@ -154,6 +174,14 @@ public:
vtkPolyData* NanSwatch;
vtkPolyDataMapper2D* NanSwatchMapper;
vtkActor2D* NanSwatchActor;
vtkPolyData* BelowRangeSwatch;
vtkPolyDataMapper2D* BelowRangeSwatchMapper;
vtkActor2D* BelowRangeSwatchActor;
vtkPolyData* AboveRangeSwatch;
vtkPolyDataMapper2D* AboveRangeSwatchMapper;
vtkActor2D* AboveRangeSwatchActor;
//@}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment