1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
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.
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.
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).
58 // Set the text property/attributes of the title and the labels through the
59 // vtkTextProperty objects associated to this actor.
62 // If a vtkLogLookupTable is specified as the lookup table to use, then the
63 // labels are created using a logarithmic scale.
66 // vtkActor2D vtkTextProperty vtkTextMapper vtkPolyDataMapper2D
68 #ifndef SMESH_SCALAR_BAR_ACTOR_H
69 #define SMESH_SCALAR_BAR_ACTOR_H
71 #include <vtkActor2D.h>
73 #include "SMESH_Object.h"
78 class vtkPolyDataMapper2D;
79 class vtkScalarsToColors;
81 class vtkTextProperty;
83 #define VTK_ORIENT_HORIZONTAL 0
84 #define VTK_ORIENT_VERTICAL 1
86 #define SMESH_MONOCOLOR_TYPE 0
87 #define SMESH_MULTICOLOR_TYPE 1
90 class SMESHOBJECT_EXPORT SMESH_ScalarBarActor: public vtkActor2D {
92 void PrintSelf(ostream& os, vtkIndent indent);
94 vtkTypeMacro(SMESH_ScalarBarActor,vtkActor2D);
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();
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);
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 *);
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
118 virtual void SetLookupTable(vtkScalarsToColors*);
119 vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
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_LARGE_INTEGER);
126 vtkGetMacro(MaximumNumberOfColors, int);
129 // Set/Get the number of annotation labels to show.
130 vtkSetClampMacro(NumberOfLabels, int, 0, 64);
131 vtkGetMacro(NumberOfLabels, int);
134 // Control the orientation of the scalar bar.
135 vtkSetClampMacro(Orientation,int,VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
136 vtkGetMacro(Orientation, int);
137 void SetOrientationToHorizontal()
138 {this->SetOrientation(VTK_ORIENT_HORIZONTAL);};
139 void SetOrientationToVertical() {this->SetOrientation(VTK_ORIENT_VERTICAL);};
142 // Set/Get the title text property.
143 virtual void SetTitleTextProperty(vtkTextProperty *p);
144 vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
147 // Set/Get the labels text property.
148 virtual void SetLabelTextProperty(vtkTextProperty *p);
149 vtkGetObjectMacro(LabelTextProperty,vtkTextProperty);
152 // Set/Get the format with which to print the labels on the scalar
154 vtkSetStringMacro(LabelFormat);
155 vtkGetStringMacro(LabelFormat);
158 // Set/Get the title of the scalar bar actor,
159 vtkSetStringMacro(Title);
160 vtkGetStringMacro(Title);
163 // Shallow copy of a scalar bar actor. Overloads the virtual vtkProp method.
164 void ShallowCopy(vtkProp *prop);
167 // Set visibility of the distribution histogram
168 // rnv: Customization of the vtkScalarBarActor to show distribution histogram:
169 virtual void SetDistributionVisibility(int flag);
172 // Set visibility of the distribution histogram
173 // rnv: Customization of the vtkScalarBarActor to show distribution histogram:
174 virtual int GetDistributionVisibility();
177 virtual void SetDistribution(std::vector<int> theNbValues);
180 // Set distribution coloring type (SMESH_MONOCOLOR_TYPE or SMESH_MULTICOLOR_TYPE)
181 void SetDistributionColoringType(int theDistributionColoringType) {myDistributionColoringType = theDistributionColoringType;Modified();}
184 // Get distribution coloring type ((SMESH_MONOCOLOR_TYPE or SMESH_MULTICOLOR_TYPE))
185 int GetDistributionColoringType() {return myDistributionColoringType;}
188 // Set Distribution Color
189 void SetDistributionColor (double rgb[3]);
192 // Get Distribution Color
193 void GetDistributionColor (double rgb[3]);
198 SMESH_ScalarBarActor();
199 ~SMESH_ScalarBarActor();
201 vtkScalarsToColors *LookupTable;
202 vtkTextProperty *TitleTextProperty;
203 vtkTextProperty *LabelTextProperty;
205 int MaximumNumberOfColors;
207 int NumberOfLabelsBuilt;
212 vtkTextMapper **TextMappers;
213 virtual void AllocateAndSizeLabels(int *labelSize, int *size,
214 vtkViewport *viewport, double *range);
219 vtkTextMapper *TitleMapper;
220 vtkActor2D *TitleActor;
222 vtkActor2D **TextActors;
224 vtkPolyData *ScalarBar;
225 vtkPolyDataMapper2D *ScalarBarMapper;
226 vtkActor2D *ScalarBarActor;
228 vtkTimeStamp BuildTime;
232 void SizeTitle(int *titleSize, int *size, vtkViewport *viewport);
234 // rnv: Customization of the vtkScalarBarActor to show distribution histogram:
235 vtkPolyData* myDistribution; //Distribution polygonal data
236 vtkActor2D* myDistributionActor; //Distribution actor
237 vtkPolyDataMapper2D* myDistributionMapper; //Distribution mapper
238 std::vector<int> myNbValues; //Nb values for the range
239 int myDistributionColoringType; //Distribution color type (monocolor or multicolor)
242 SMESH_ScalarBarActor(const SMESH_ScalarBarActor&); // Not implemented.
243 void operator=(const SMESH_ScalarBarActor&); // Not implemented.
246 #endif //SMESH_SCALAR_BAR_ACTOR_H