1 // Copyright (C) 2007-2008 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
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File: VISU_PipeLine.hxx
24 // Author: Alexey PETROV
27 #ifndef VISU_ScalarBarActor_HeaderFile
28 #define VISU_ScalarBarActor_HeaderFile
30 #include "VISUPipeline.hxx"
31 #include "VISU_LookupTable.hxx"
32 #include "VISU_XYPlotActor.hxx"
34 #include <vtkActor2D.h>
35 #include <vtkDoubleArray.h> // RKV
38 class vtkPolyDataMapper2D;
39 class vtkScalarsToColors;
41 class vtkTextProperty;
43 #ifndef VTK_ORIENT_HORIZONTAL
44 #define VTK_ORIENT_HORIZONTAL 0
47 #ifndef VTK_ORIENT_VERTICAL
48 #define VTK_ORIENT_VERTICAL 1
51 class VISU_PIPELINE_EXPORT VISU_ScalarBarActor : public vtkActor2D
54 vtkTypeRevisionMacro(VISU_ScalarBarActor,vtkActor2D);
55 void PrintSelf(ostream& os, vtkIndent indent);
58 // Instantiate object with 64 maximum colors; 5 labels; %%-#6.3g label
59 // format, no title, and vertical orientation. The initial scalar bar
60 // size is (0.05 x 0.8) of the viewport size.
61 static VISU_ScalarBarActor *New();
64 // Draw the scalar bar and annotation text to the screen.
65 int RenderOpaqueGeometry(vtkViewport* viewport);
66 int RenderTranslucentGeometry(vtkViewport*) { return 0; };
67 int RenderOverlay(vtkViewport* viewport);
70 // Release any graphics resources that are being consumed by this actor.
71 // The parameter window could be used to determine which graphic
72 // resources to release.
73 virtual void ReleaseGraphicsResources(vtkWindow *);
76 // Set/Get the vtkLookupTable to use. The lookup table specifies the number
77 // of colors to use in the table (if not overridden), as well as the scalar
79 virtual void SetLookupTable(VISU_LookupTable*);
80 vtkGetObjectMacro(LookupTable,VISU_LookupTable);
83 // Set/Get the maximum number of scalar bar segments to show. This may
84 // differ from the number of colors in the lookup table, in which case
85 // the colors are samples from the lookup table.
86 vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_LARGE_INTEGER);
87 vtkGetMacro(MaximumNumberOfColors, int);
90 // Set/Get the number of annotation labels to show.
91 vtkSetClampMacro(NumberOfLabels, int, 0, 64);
92 vtkGetMacro(NumberOfLabels, int);
95 // Control the orientation of the scalar bar.
96 vtkSetClampMacro(Orientation,int,VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL);
97 vtkGetMacro(Orientation, int);
98 void SetOrientationToHorizontal()
99 {this->SetOrientation(VTK_ORIENT_HORIZONTAL);};
100 void SetOrientationToVertical() {this->SetOrientation(VTK_ORIENT_VERTICAL);};
103 // Set/Get the title text property.
104 virtual void SetTitleTextProperty(vtkTextProperty *p);
105 vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
108 // Set/Get the labels text property.
109 virtual void SetLabelTextProperty(vtkTextProperty *p);
110 vtkGetObjectMacro(LabelTextProperty,vtkTextProperty);
114 // Set/Get the values distribution array
115 virtual void SetDistribution(vtkDoubleArray *d);
116 vtkGetObjectMacro(Distribution,vtkDoubleArray);
119 // Set/Get the flag of distribution plot visibility
120 void SetDistributionVisibility(int v);
121 vtkGetMacro(DistributionVisibility, int);
122 void DistributionVisibilityOn()
123 {this->SetDistributionVisibility(1);};
124 void DistributionVisibilityOff() {this->SetDistributionVisibility(0);};
131 // Set/Get the scalar bar dimention properties in persents.
132 // 0 <= ration <= 100
133 void SetRatios(int titleRatioSize,int labelRatioWidth,
134 int barRatioWidth, int barRatioHeight);
135 void GetRatios(int& titleRatioSize, int& labelRatioWidth,
136 int& barRatioWidth, int& barRatioHeight);
139 // Set/Get the format with which to print the labels on the scalar
141 vtkSetStringMacro(LabelFormat);
142 vtkGetStringMacro(LabelFormat);
145 // Set/Get the title of the scalar bar actor,
146 vtkSetStringMacro(Title);
147 vtkGetStringMacro(Title);
150 // Shallow copy of a scalar bar actor. Overloads the virtual vtkProp method.
151 void ShallowCopy(vtkProp *prop);
154 VISU_ScalarBarActor();
155 ~VISU_ScalarBarActor();
157 VISU_LookupTable *LookupTable;
158 vtkTextProperty *TitleTextProperty;
159 vtkTextProperty *LabelTextProperty;
161 /** Array for keeping the distribution of colors within cells.
162 * For each color index the appropriate element of the array contains
163 * a number of cells for this color.*/
164 vtkDoubleArray *Distribution; // RKV
165 /** Visibility flag for the distribution plot */
166 int DistributionVisibility; // RKV
168 int MaximumNumberOfColors;
170 int NumberOfLabelsBuilt;
179 vtkTextMapper **TextMappers;
180 virtual void AllocateAndSizeLabels(int *labelSize, int *size,
181 vtkViewport *viewport, vtkFloatingPointType *range);
184 vtkTextMapper *TitleMapper;
185 vtkActor2D *TitleActor;
187 vtkActor2D **TextActors;
189 vtkPolyData *ScalarBar;
190 vtkPolyDataMapper2D *ScalarBarMapper;
191 vtkActor2D *ScalarBarActor;
193 vtkDataObject *DistributionObj; // RKV
194 VISU_XYPlotActor *DistributionActor; // RKV
196 vtkTimeStamp BuildTime;
200 void SizeTitle(int *titleSize, int *size, vtkViewport *viewport);
202 void SizeBar(int& barSizeWidth, int& barSizeHeight, int *size,
203 vtkViewport *viewport, vtkFloatingPointType *range);
205 /** Place the distribution plot actor in the viewport according to the
206 * scalar bar location and orientation */
207 void PlaceDistribution(vtkViewport *viewport, const int barWidth, const int barHeight);
210 VISU_ScalarBarActor(const VISU_ScalarBarActor&); // Not implemented.
211 void operator=(const VISU_ScalarBarActor&); // Not implemented.