Salome HOME
23422: EDF 14312 - Strange behavior of Viscous Layer Surface offset + smooth
[modules/smesh.git] / src / OBJECT / SMESH_ScalarBarActor.h
1 // Copyright (C) 2007-2016  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, 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
77 class vtkPolyData;
78 class vtkPolyDataMapper2D;
79 class vtkScalarsToColors;
80 class vtkTextMapper;
81 class 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
90 class SMESHOBJECT_EXPORT SMESH_ScalarBarActor: public vtkActor2D {
91  public:
92   void PrintSelf(ostream& os, vtkIndent indent);
93
94   vtkTypeMacro(SMESH_ScalarBarActor,vtkActor2D);
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.
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);};
140
141   // Description:
142   // Set/Get the title text property.
143   virtual void SetTitleTextProperty(vtkTextProperty *p);
144   vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
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,
159   vtkSetStringMacro(Title);
160   vtkGetStringMacro(Title);
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:
204   SMESH_ScalarBarActor();
205   ~SMESH_ScalarBarActor();
206   
207   vtkScalarsToColors *LookupTable;
208   vtkTextProperty *TitleTextProperty;
209   vtkTextProperty *LabelTextProperty;
210   
211   int   MaximumNumberOfColors;
212   int   NumberOfLabels;
213   int   NumberOfLabelsBuilt;
214   int   Orientation;
215   char  *Title;
216   char  *LabelFormat;
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;
226   vtkActor2D    *TitleActor;
227
228   vtkActor2D    **TextActors;
229
230   vtkPolyData         *ScalarBar;
231   vtkPolyDataMapper2D *ScalarBarMapper;
232   vtkActor2D          *ScalarBarActor;
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