1 // Copyright (C) 2007-2012 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.
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 // VISU OBJECT : interactive object for VISU entities implementation
24 // File: VISU_PipeLine.hxx
25 // Author: Alexey PETROV
28 #ifndef VISU_ScalarBarActor_HeaderFile
29 #define VISU_ScalarBarActor_HeaderFile
31 #include "VISUPipeline.hxx"
32 #include "VISU_LookupTable.hxx"
33 #include "VISU_XYPlotActor.hxx"
35 #include <vtkActor2D.h>
36 #include <vtkDoubleArray.h> // RKV
39 class vtkPolyDataMapper2D;
40 class vtkScalarsToColors;
42 class vtkTextProperty;
44 #ifndef VTK_ORIENT_HORIZONTAL
45 #define VTK_ORIENT_HORIZONTAL 0
48 #ifndef VTK_ORIENT_VERTICAL
49 #define VTK_ORIENT_VERTICAL 1
52 class VISU_PIPELINE_EXPORT VISU_ScalarBarActor : public vtkActor2D
55 vtkTypeRevisionMacro(VISU_ScalarBarActor,vtkActor2D);
56 void PrintSelf(ostream& os, vtkIndent indent);
59 // Instantiate object with 64 maximum colors; 5 labels; %%-#6.3g label
60 // format, no title, and vertical orientation. The initial scalar bar
61 // size is (0.05 x 0.8) of the viewport size.
62 static VISU_ScalarBarActor *New();
65 // Draw the scalar bar and annotation text to the screen.
66 int RenderOpaqueGeometry(vtkViewport* viewport);
67 int RenderTranslucentGeometry(vtkViewport*) { return 0; };
68 int RenderOverlay(vtkViewport* viewport);
71 // Release any graphics resources that are being consumed by this actor.
72 // The parameter window could be used to determine which graphic
73 // resources to release.
74 virtual void ReleaseGraphicsResources(vtkWindow *);
77 // Set/Get the vtkLookupTable to use. The lookup table specifies the number
78 // of colors to use in the table (if not overridden), as well as the scalar
80 virtual void SetLookupTable(VISU_LookupTable*);
81 vtkGetObjectMacro(LookupTable,VISU_LookupTable);
84 // Set/Get the maximum number of scalar bar segments to show. This may
85 // differ from the number of colors in the lookup table, in which case
86 // the colors are samples from the lookup table.
87 vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_LARGE_INTEGER);
88 vtkGetMacro(MaximumNumberOfColors, int);
91 // Set/Get the number of annotation labels to show.
92 vtkSetClampMacro(NumberOfLabels, int, 0, 64);
93 vtkGetMacro(NumberOfLabels, int);
96 // Control the orientation of the scalar bar.
97 vtkSetClampMacro(Orientation,int,VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
98 vtkGetMacro(Orientation, int);
99 void SetOrientationToHorizontal()
100 {this->SetOrientation(VTK_ORIENT_HORIZONTAL);};
101 void SetOrientationToVertical() {this->SetOrientation(VTK_ORIENT_VERTICAL);};
104 // Set/Get the title text property.
105 virtual void SetTitleTextProperty(vtkTextProperty *p);
106 vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
109 // Set/Get the labels text property.
110 virtual void SetLabelTextProperty(vtkTextProperty *p);
111 vtkGetObjectMacro(LabelTextProperty,vtkTextProperty);
115 // Set/Get the values distribution array
116 virtual void SetDistribution(vtkDoubleArray *d);
117 vtkGetObjectMacro(Distribution,vtkDoubleArray);
120 // Set/Get the flag of distribution plot visibility
121 void SetDistributionVisibility(int v);
122 vtkGetMacro(DistributionVisibility, int);
123 void DistributionVisibilityOn()
124 {this->SetDistributionVisibility(1);};
125 void DistributionVisibilityOff() {this->SetDistributionVisibility(0);};
132 // Set/Get the scalar bar dimention properties in persents.
133 // 0 <= ration <= 100
134 void SetRatios(int titleRatioSize,int labelRatioWidth,
135 int barRatioWidth, int barRatioHeight);
136 void GetRatios(int& titleRatioSize, int& labelRatioWidth,
137 int& barRatioWidth, int& barRatioHeight);
140 // Set/Get the format with which to print the labels on the scalar
142 vtkSetStringMacro(LabelFormat);
143 vtkGetStringMacro(LabelFormat);
146 // Set/Get the title of the scalar bar actor,
147 vtkSetStringMacro(Title);
148 vtkGetStringMacro(Title);
151 // Shallow copy of a scalar bar actor. Overloads the virtual vtkProp method.
152 void ShallowCopy(vtkProp *prop);
155 VISU_ScalarBarActor();
156 ~VISU_ScalarBarActor();
158 VISU_LookupTable *LookupTable;
159 vtkTextProperty *TitleTextProperty;
160 vtkTextProperty *LabelTextProperty;
162 /** Array for keeping the distribution of colors within cells.
163 * For each color index the appropriate element of the array contains
164 * a number of cells for this color.*/
165 vtkDoubleArray *Distribution; // RKV
166 /** Visibility flag for the distribution plot */
167 int DistributionVisibility; // RKV
169 int MaximumNumberOfColors;
171 int NumberOfLabelsBuilt;
180 vtkTextMapper **TextMappers;
181 virtual void AllocateAndSizeLabels(int *labelSize, int *size,
182 vtkViewport *viewport, vtkFloatingPointType *range);
185 vtkTextMapper *TitleMapper;
186 vtkActor2D *TitleActor;
188 vtkActor2D **TextActors;
190 vtkPolyData *ScalarBar;
191 vtkPolyDataMapper2D *ScalarBarMapper;
192 vtkActor2D *ScalarBarActor;
194 vtkDataObject *DistributionObj; // RKV
195 VISU_XYPlotActor *DistributionActor; // RKV
197 vtkTimeStamp BuildTime;
201 void SizeTitle(int *titleSize, int *size, vtkViewport *viewport);
203 void SizeBar(int& barSizeWidth, int& barSizeHeight, int *size,
204 vtkViewport *viewport, vtkFloatingPointType *range);
206 /** Place the distribution plot actor in the viewport according to the
207 * scalar bar location and orientation */
208 void PlaceDistribution(vtkViewport *viewport, const int barWidth, const int barHeight);
211 VISU_ScalarBarActor(const VISU_ScalarBarActor&); // Not implemented.
212 void operator=(const VISU_ScalarBarActor&); // Not implemented.