Version: 9.16.0
SMESH_ScalarBarActor.h
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, OPEN CASCADE
2//
3// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5//
6// This library is free software; you can redistribute it and/or
7// modify it under the terms of the GNU Lesser General Public
8// License as published by the Free Software Foundation; either
9// version 2.1 of the License, or (at your option) any later version.
10//
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public
17// License along with this library; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19//
20// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21//
22
23// SMESH SCALAR BAR : 2D Actor for the visualization scalar bar with the distribution diagram
24// it is customized vtkScalarBarActor.
25// File : SMESH_ScalarBarActor.h
26// Author : Roman NIKOLAEV
27// Module : SMESH
28
29
30// .NAME vtkScalarBarActor - Create a scalar bar with labels
31// .SECTION Description
32// vtkScalarBarActor creates a scalar bar with annotation text. A scalar
33// bar is a legend that indicates to the viewer the correspondence between
34// color value and data value. The legend consists of a rectangular bar
35// made of rectangular pieces each colored a constant value. Since
36// vtkScalarBarActor is a subclass of vtkActor2D, it is drawn in the image
37// plane (i.e., in the renderer's viewport) on top of the 3D graphics window.
38//
39// To use vtkScalarBarActor you must associate a vtkScalarsToColors (or
40// subclass) with it. The lookup table defines the colors and the
41// range of scalar values used to map scalar data. Typically, the
42// number of colors shown in the scalar bar is not equal to the number
43// of colors in the lookup table, in which case sampling of
44// the lookup table is performed.
45//
46// Other optional capabilities include specifying the fraction of the
47// viewport size (both x and y directions) which will control the size
48// of the scalar bar and the number of annotation labels. The actual position
49// of the scalar bar on the screen is controlled by using the
50// vtkActor2D::SetPosition() method (by default the scalar bar is
51// centered in the viewport). Other features include the ability to
52// orient the scalar bar horizontally of vertically and controlling
53// the format (printf style) with which to print the labels on the
54// scalar bar. Also, the vtkScalarBarActor's property is applied to
55// the scalar bar and annotation (including layer, and
56// compositing operator).
57//
58// Set the text property/attributes of the title and the labels through the
59// vtkTextProperty objects associated to this actor.
60//
61// .SECTION Caveats
62// If a vtkLogLookupTable is specified as the lookup table to use, then the
63// labels are created using a logarithmic scale.
64//
65// .SECTION See Also
66// vtkActor2D vtkTextProperty vtkTextMapper vtkPolyDataMapper2D
67
68#ifndef SMESH_SCALAR_BAR_ACTOR_H
69#define SMESH_SCALAR_BAR_ACTOR_H
70
71#include <vtkActor2D.h>
72
73#include "SMESH_Object.h"
74
75#include <vector>
76
77class vtkPolyData;
78class vtkPolyDataMapper2D;
79class vtkScalarsToColors;
80class vtkTextMapper;
81class vtkTextProperty;
82
83#define VTK_ORIENT_HORIZONTAL 0
84#define VTK_ORIENT_VERTICAL 1
85
86#define SMESH_MONOCOLOR_TYPE 0
87#define SMESH_MULTICOLOR_TYPE 1
88
89
91 public:
92 void PrintSelf(ostream& os, vtkIndent indent);
93
95
96 // Description:
97 // Instantiate object with 64 maximum colors; 5 labels; %%-#6.3g label
98 // format, no title, and vertical orientation. The initial scalar bar
99 // size is (0.05 x 0.8) of the viewport size.
100 static SMESH_ScalarBarActor *New();
101
102 // Description:
103 // Draw the scalar bar and annotation text to the screen.
104 int RenderOpaqueGeometry(vtkViewport* viewport);
105 int RenderTranslucentGeometry(vtkViewport*) { return 0; };
106 int RenderOverlay(vtkViewport* viewport);
107
108 // Description:
109 // Release any graphics resources that are being consumed by this actor.
110 // The parameter window could be used to determine which graphic
111 // resources to release.
112 virtual void ReleaseGraphicsResources(vtkWindow *);
113
114 // Description:
115 // Set/Get the vtkLookupTable to use. The lookup table specifies the number
116 // of colors to use in the table (if not overridden), as well as the scalar
117 // range.
118 virtual void SetLookupTable(vtkScalarsToColors*);
119 vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
120
121 // Description:
122 // Set/Get the maximum number of scalar bar segments to show. This may
123 // differ from the number of colors in the lookup table, in which case
124 // the colors are samples from the lookup table.
125 vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_INT_MAX);
126 vtkGetMacro(MaximumNumberOfColors, int);
127
128 // Description:
129 // Set/Get the number of annotation labels to show.
130 vtkSetClampMacro(NumberOfLabels, int, 0, 64);
131 vtkGetMacro(NumberOfLabels, int);
132
133 // Description:
134 // Control the orientation of the scalar bar.
138 {this->SetOrientation(VTK_ORIENT_HORIZONTAL);};
139 void SetOrientationToVertical() {this->SetOrientation(VTK_ORIENT_VERTICAL);};
140
141 // Description:
142 // Set/Get the title text property.
143 virtual void SetTitleTextProperty(vtkTextProperty *p);
145
146 // Description:
147 // Set/Get the labels text property.
148 virtual void SetLabelTextProperty(vtkTextProperty *p);
149 vtkGetObjectMacro(LabelTextProperty,vtkTextProperty);
150
151 // Description:
152 // Set/Get the format with which to print the labels on the scalar
153 // bar.
154 vtkSetStringMacro(LabelFormat);
155 vtkGetStringMacro(LabelFormat);
156
157 // Description:
158 // Set/Get the title of the scalar bar actor,
161
162 // Description:
163 // Shallow copy of a scalar bar actor. Overloads the virtual vtkProp method.
164 void ShallowCopy(vtkProp *prop);
165
166 // Description:
167 // Set visibility of the distribution histogram
168 // rnv: Customization of the vtkScalarBarActor to show distribution histogram:
169 virtual void SetDistributionVisibility(int flag);
170
171 // Description:
172 // Set visibility of the distribution histogram
173 // rnv: Customization of the vtkScalarBarActor to show distribution histogram:
174 virtual int GetDistributionVisibility();
175 // Description:
176 // Set distribution
177 virtual void SetDistribution(const std::vector<int>& theNbValues);
178
179 // Description:
180 // Set distribution coloring type (SMESH_MONOCOLOR_TYPE or SMESH_MULTICOLOR_TYPE)
181 void SetDistributionColoringType(int theDistributionColoringType) {myDistributionColoringType = theDistributionColoringType;Modified();}
182
183 // Description:
184 // Get distribution coloring type ((SMESH_MONOCOLOR_TYPE or SMESH_MULTICOLOR_TYPE))
185 int GetDistributionColoringType() {return myDistributionColoringType;}
186
187 // Description:
188 // Set Distribution Color
189 void SetDistributionColor (double rgb[3]);
190
191 // Description:
192 // Get Distribution Color
193 void GetDistributionColor (double rgb[3]);
194
195 // Description:
196 // Set visibility status of scalar map
197 void SetTitleOnlyVisibility( bool );
198
199 // Description:
200 // Get visibility status of scalar map
201 bool GetTitleOnlyVisibility();
202
203 protected:
206
207 vtkScalarsToColors *LookupTable;
208 vtkTextProperty *TitleTextProperty;
209 vtkTextProperty *LabelTextProperty;
210
215 char *Title;
217
218 vtkTextMapper **TextMappers;
219 virtual void AllocateAndSizeLabels(int *labelSize, int *size,
220 vtkViewport *viewport, double *range);
221
222
223
224 private:
225 vtkTextMapper *TitleMapper;
227
229
230 vtkPolyData *ScalarBar;
231 vtkPolyDataMapper2D *ScalarBarMapper;
233
234 vtkTimeStamp BuildTime;
235 int LastSize[2];
236 int LastOrigin[2];
237
238 void SizeTitle(int *titleSize, int *size, vtkViewport *viewport);
239
240 // rnv: Customization of the vtkScalarBarActor to show distribution histogram:
241 vtkPolyData* myDistribution; //Distribution polygonal data
242 vtkActor2D* myDistributionActor; //Distribution actor
243 vtkPolyDataMapper2D* myDistributionMapper; //Distribution mapper
244 std::vector<int> myNbValues; //Nb values for the range
245 int myDistributionColoringType; //Distribution color type (monocolor or multicolor)
246 bool myTitleOnlyVisibility; //Show scalar map or not
247
248 private:
249 SMESH_ScalarBarActor(const SMESH_ScalarBarActor&); // Not implemented.
250 void operator=(const SMESH_ScalarBarActor&); // Not implemented.
251};
252
253#endif //SMESH_SCALAR_BAR_ACTOR_H
#define SMESHOBJECT_EXPORT
Definition: SMESH_Object.h:38
vtkScalarsToColors TitleTextProperty
Definition: SMESH_ScalarBarActor.cxx:48
LookupTable
Definition: SMESH_ScalarBarActor.cxx:46
#define VTK_ORIENT_VERTICAL
Definition: SMESH_ScalarBarActor.h:84
#define VTK_ORIENT_HORIZONTAL
Definition: SMESH_ScalarBarActor.h:83
Definition: SMESH_ScalarBarActor.h:90
vtkGetMacro(Orientation, int)
virtual void SetTitleTextProperty(vtkTextProperty *p)
virtual void SetLookupTable(vtkScalarsToColors *)
void SetOrientationToHorizontal()
Definition: SMESH_ScalarBarActor.h:137
void SetDistributionColoringType(int theDistributionColoringType)
Definition: SMESH_ScalarBarActor.h:181
char * Title
Definition: SMESH_ScalarBarActor.h:215
void operator=(const SMESH_ScalarBarActor &)
vtkPolyDataMapper2D * myDistributionMapper
Definition: SMESH_ScalarBarActor.h:243
void SetOrientationToVertical()
Definition: SMESH_ScalarBarActor.h:139
vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_INT_MAX)
char * LabelFormat
Definition: SMESH_ScalarBarActor.h:216
vtkPolyDataMapper2D * ScalarBarMapper
Definition: SMESH_ScalarBarActor.h:231
vtkGetObjectMacro(LabelTextProperty, vtkTextProperty)
int GetDistributionColoringType()
Definition: SMESH_ScalarBarActor.h:185
vtkGetObjectMacro(LookupTable, vtkScalarsToColors)
vtkTextProperty * LabelTextProperty
Definition: SMESH_ScalarBarActor.h:209
vtkActor2D * TitleActor
Definition: SMESH_ScalarBarActor.h:226
vtkTimeStamp BuildTime
Definition: SMESH_ScalarBarActor.h:234
vtkActor2D ** TextActors
Definition: SMESH_ScalarBarActor.h:228
vtkTextMapper * TitleMapper
Definition: SMESH_ScalarBarActor.h:225
int RenderTranslucentGeometry(vtkViewport *)
Definition: SMESH_ScalarBarActor.h:105
vtkGetStringMacro(LabelFormat)
vtkTextMapper ** TextMappers
Definition: SMESH_ScalarBarActor.h:218
vtkTextProperty * TitleTextProperty
Definition: SMESH_ScalarBarActor.h:208
vtkGetMacro(NumberOfLabels, int)
int NumberOfLabelsBuilt
Definition: SMESH_ScalarBarActor.h:213
int myDistributionColoringType
Definition: SMESH_ScalarBarActor.h:245
vtkActor2D * myDistributionActor
Definition: SMESH_ScalarBarActor.h:242
vtkPolyData * myDistribution
Definition: SMESH_ScalarBarActor.h:241
int NumberOfLabels
Definition: SMESH_ScalarBarActor.h:212
int Orientation
Definition: SMESH_ScalarBarActor.h:214
vtkScalarsToColors * LookupTable
Definition: SMESH_ScalarBarActor.h:207
virtual void SetLabelTextProperty(vtkTextProperty *p)
SMESH_ScalarBarActor(const SMESH_ScalarBarActor &)
vtkTypeMacro(SMESH_ScalarBarActor, vtkActor2D) static SMESH_ScalarBarActor *New()
vtkActor2D * ScalarBarActor
Definition: SMESH_ScalarBarActor.h:232
vtkSetClampMacro(Orientation, int, 0, 1)
int MaximumNumberOfColors
Definition: SMESH_ScalarBarActor.h:211
vtkSetStringMacro(LabelFormat)
bool myTitleOnlyVisibility
Definition: SMESH_ScalarBarActor.h:246
vtkPolyData * ScalarBar
Definition: SMESH_ScalarBarActor.h:230
vtkGetObjectMacro(TitleTextProperty, vtkTextProperty)
vtkSetClampMacro(NumberOfLabels, int, 0, 64)
vtkGetMacro(MaximumNumberOfColors, int)
std::vector< int > myNbValues
Definition: SMESH_ScalarBarActor.h:244
Orientation
Definition: SMESHGUI_ClippingDlg.h:75