Salome HOME
Update copyright information
[modules/visu.git] / src / PIPELINE / VISU_ScalarBarActor.hxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, 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.
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 //  VISU OBJECT : interactive object for VISU entities implementation
24 // File:    VISU_PipeLine.hxx
25 // Author:  Alexey PETROV
26 // Module : VISU
27 //
28 #ifndef VISU_ScalarBarActor_HeaderFile
29 #define VISU_ScalarBarActor_HeaderFile
30
31 #include "VISUPipeline.hxx"
32 #include "VISU_LookupTable.hxx"
33 #include "VISU_XYPlotActor.hxx"
34
35 #include <vtkActor2D.h>
36 #include <vtkDoubleArray.h> // RKV
37
38 class vtkPolyData;
39 class vtkPolyDataMapper2D;
40 class vtkScalarsToColors;
41 class vtkTextMapper;
42 class vtkTextProperty;
43
44 #ifndef VTK_ORIENT_HORIZONTAL
45 #define VTK_ORIENT_HORIZONTAL 0
46 #endif
47
48 #ifndef VTK_ORIENT_VERTICAL
49 #define VTK_ORIENT_VERTICAL 1
50 #endif
51
52 class VISU_PIPELINE_EXPORT VISU_ScalarBarActor : public vtkActor2D
53 {
54 public:
55   vtkTypeRevisionMacro(VISU_ScalarBarActor,vtkActor2D);
56   void PrintSelf(ostream& os, vtkIndent indent);
57
58   // Description:
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();
63
64   // Description:
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);
69
70   // Description:
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 *);
75
76   // Description:
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
79   // range.
80   virtual void SetLookupTable(VISU_LookupTable*);
81   vtkGetObjectMacro(LookupTable,VISU_LookupTable);
82
83   // Description:
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);
89   
90   // Description:
91   // Set/Get the number of annotation labels to show.
92   vtkSetClampMacro(NumberOfLabels, int, 0, 64);
93   vtkGetMacro(NumberOfLabels, int);
94   
95   // Description:
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);};
102
103   // Description:
104   // Set/Get the title text property.
105   virtual void SetTitleTextProperty(vtkTextProperty *p);
106   vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
107   
108   // Description:
109   // Set/Get the labels text property.
110   virtual void SetLabelTextProperty(vtkTextProperty *p);
111   vtkGetObjectMacro(LabelTextProperty,vtkTextProperty);
112
113 // RKV : Begin
114   // Description:
115   // Set/Get the values distribution array
116   virtual void SetDistribution(vtkDoubleArray *d);
117   vtkGetObjectMacro(Distribution,vtkDoubleArray);
118   
119   // Description:
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);};
126
127   void DebugOn();
128   void DebugOff();
129 // RKV : End
130     
131   // Description:
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);
138
139   // Description:
140   // Set/Get the format with which to print the labels on the scalar
141   // bar.
142   vtkSetStringMacro(LabelFormat);
143   vtkGetStringMacro(LabelFormat);
144
145   // Description:
146   // Set/Get the title of the scalar bar actor,
147   vtkSetStringMacro(Title);
148   vtkGetStringMacro(Title);
149
150   // Description:
151   // Shallow copy of a scalar bar actor. Overloads the virtual vtkProp method.
152   void ShallowCopy(vtkProp *prop);
153
154 protected:
155   VISU_ScalarBarActor();
156   ~VISU_ScalarBarActor();
157
158   VISU_LookupTable *LookupTable;
159   vtkTextProperty *TitleTextProperty;
160   vtkTextProperty *LabelTextProperty;
161   
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
168
169   int   MaximumNumberOfColors;
170   int   NumberOfLabels;
171   int   NumberOfLabelsBuilt;
172   int   Orientation;
173   char  *Title;
174   char  *LabelFormat;
175   int   TitleRatioSize;
176   int   LabelRatioWidth;
177   int   BarRatioWidth;
178   int   BarRatioHeight;
179
180   vtkTextMapper **TextMappers;
181   virtual void AllocateAndSizeLabels(int *labelSize, int *size,
182                                      vtkViewport *viewport, vtkFloatingPointType *range);
183
184 private:
185   vtkTextMapper *TitleMapper;
186   vtkActor2D    *TitleActor;
187
188   vtkActor2D    **TextActors;
189
190   vtkPolyData         *ScalarBar;
191   vtkPolyDataMapper2D *ScalarBarMapper;
192   vtkActor2D          *ScalarBarActor;
193
194   vtkDataObject       *DistributionObj; // RKV
195   VISU_XYPlotActor    *DistributionActor; // RKV
196
197   vtkTimeStamp  BuildTime;
198   int LastSize[2];
199   int LastOrigin[2];
200
201   void SizeTitle(int *titleSize, int *size, vtkViewport *viewport);
202
203   void SizeBar(int& barSizeWidth, int& barSizeHeight, int *size,
204                vtkViewport *viewport, vtkFloatingPointType *range);
205                
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);
209
210 private:
211   VISU_ScalarBarActor(const VISU_ScalarBarActor&);  // Not implemented.
212   void operator=(const VISU_ScalarBarActor&);  // Not implemented.
213 };
214
215 #endif