00001 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE 00002 // 00003 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, 00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 00005 // 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 2.1 of the License. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with this library; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 // 00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00021 // 00022 00023 // SMESH SCALAR BAR : 2D Actor for the visualization scalar bar with the distribution diagram 00024 // it is customized vtkScalarBarActor. 00025 // File : SMESH_ScalarBarActor.h 00026 // Author : Roman NIKOLAEV 00027 // Module : SMESH 00028 00029 00030 // .NAME vtkScalarBarActor - Create a scalar bar with labels 00031 // .SECTION Description 00032 // vtkScalarBarActor creates a scalar bar with annotation text. A scalar 00033 // bar is a legend that indicates to the viewer the correspondence between 00034 // color value and data value. The legend consists of a rectangular bar 00035 // made of rectangular pieces each colored a constant value. Since 00036 // vtkScalarBarActor is a subclass of vtkActor2D, it is drawn in the image 00037 // plane (i.e., in the renderer's viewport) on top of the 3D graphics window. 00038 // 00039 // To use vtkScalarBarActor you must associate a vtkScalarsToColors (or 00040 // subclass) with it. The lookup table defines the colors and the 00041 // range of scalar values used to map scalar data. Typically, the 00042 // number of colors shown in the scalar bar is not equal to the number 00043 // of colors in the lookup table, in which case sampling of 00044 // the lookup table is performed. 00045 // 00046 // Other optional capabilities include specifying the fraction of the 00047 // viewport size (both x and y directions) which will control the size 00048 // of the scalar bar and the number of annotation labels. The actual position 00049 // of the scalar bar on the screen is controlled by using the 00050 // vtkActor2D::SetPosition() method (by default the scalar bar is 00051 // centered in the viewport). Other features include the ability to 00052 // orient the scalar bar horizontally of vertically and controlling 00053 // the format (printf style) with which to print the labels on the 00054 // scalar bar. Also, the vtkScalarBarActor's property is applied to 00055 // the scalar bar and annotation (including layer, and 00056 // compositing operator). 00057 // 00058 // Set the text property/attributes of the title and the labels through the 00059 // vtkTextProperty objects associated to this actor. 00060 // 00061 // .SECTION Caveats 00062 // If a vtkLogLookupTable is specified as the lookup table to use, then the 00063 // labels are created using a logarithmic scale. 00064 // 00065 // .SECTION See Also 00066 // vtkActor2D vtkTextProperty vtkTextMapper vtkPolyDataMapper2D 00067 00068 #ifndef SMESH_SCALAR_BAR_ACTOR_H 00069 #define SMESH_SCALAR_BAR_ACTOR_H 00070 00071 #include <vtkActor2D.h> 00072 00073 #include "SMESH_Object.h" 00074 00075 #include <vector> 00076 00077 class vtkPolyData; 00078 class vtkPolyDataMapper2D; 00079 class vtkScalarsToColors; 00080 class vtkTextMapper; 00081 class vtkTextProperty; 00082 00083 #define VTK_ORIENT_HORIZONTAL 0 00084 #define VTK_ORIENT_VERTICAL 1 00085 00086 #define SMESH_MONOCOLOR_TYPE 0 00087 #define SMESH_MULTICOLOR_TYPE 1 00088 00089 00090 class SMESHOBJECT_EXPORT SMESH_ScalarBarActor: public vtkActor2D { 00091 public: 00092 void PrintSelf(ostream& os, vtkIndent indent); 00093 00094 vtkTypeMacro(SMESH_ScalarBarActor,vtkActor2D); 00095 00096 // Description: 00097 // Instantiate object with 64 maximum colors; 5 labels; %%-#6.3g label 00098 // format, no title, and vertical orientation. The initial scalar bar 00099 // size is (0.05 x 0.8) of the viewport size. 00100 static SMESH_ScalarBarActor *New(); 00101 00102 // Description: 00103 // Draw the scalar bar and annotation text to the screen. 00104 int RenderOpaqueGeometry(vtkViewport* viewport); 00105 int RenderTranslucentGeometry(vtkViewport*) { return 0; }; 00106 int RenderOverlay(vtkViewport* viewport); 00107 00108 // Description: 00109 // Release any graphics resources that are being consumed by this actor. 00110 // The parameter window could be used to determine which graphic 00111 // resources to release. 00112 virtual void ReleaseGraphicsResources(vtkWindow *); 00113 00114 // Description: 00115 // Set/Get the vtkLookupTable to use. The lookup table specifies the number 00116 // of colors to use in the table (if not overridden), as well as the scalar 00117 // range. 00118 virtual void SetLookupTable(vtkScalarsToColors*); 00119 vtkGetObjectMacro(LookupTable,vtkScalarsToColors); 00120 00121 // Description: 00122 // Set/Get the maximum number of scalar bar segments to show. This may 00123 // differ from the number of colors in the lookup table, in which case 00124 // the colors are samples from the lookup table. 00125 vtkSetClampMacro(MaximumNumberOfColors, int, 2, VTK_LARGE_INTEGER); 00126 vtkGetMacro(MaximumNumberOfColors, int); 00127 00128 // Description: 00129 // Set/Get the number of annotation labels to show. 00130 vtkSetClampMacro(NumberOfLabels, int, 0, 64); 00131 vtkGetMacro(NumberOfLabels, int); 00132 00133 // Description: 00134 // Control the orientation of the scalar bar. 00135 vtkSetClampMacro(Orientation,int,VTK_ORIENT_HORIZONTAL, VTK_ORIENT_VERTICAL); 00136 vtkGetMacro(Orientation, int); 00137 void SetOrientationToHorizontal() 00138 {this->SetOrientation(VTK_ORIENT_HORIZONTAL);}; 00139 void SetOrientationToVertical() {this->SetOrientation(VTK_ORIENT_VERTICAL);}; 00140 00141 // Description: 00142 // Set/Get the title text property. 00143 virtual void SetTitleTextProperty(vtkTextProperty *p); 00144 vtkGetObjectMacro(TitleTextProperty,vtkTextProperty); 00145 00146 // Description: 00147 // Set/Get the labels text property. 00148 virtual void SetLabelTextProperty(vtkTextProperty *p); 00149 vtkGetObjectMacro(LabelTextProperty,vtkTextProperty); 00150 00151 // Description: 00152 // Set/Get the format with which to print the labels on the scalar 00153 // bar. 00154 vtkSetStringMacro(LabelFormat); 00155 vtkGetStringMacro(LabelFormat); 00156 00157 // Description: 00158 // Set/Get the title of the scalar bar actor, 00159 vtkSetStringMacro(Title); 00160 vtkGetStringMacro(Title); 00161 00162 // Description: 00163 // Shallow copy of a scalar bar actor. Overloads the virtual vtkProp method. 00164 void ShallowCopy(vtkProp *prop); 00165 00166 // Description: 00167 // Set visibility of the distribution histogram 00168 // rnv: Customization of the vtkScalarBarActor to show distribution histogram: 00169 virtual void SetDistributionVisibility(int flag); 00170 00171 // Description: 00172 // Set visibility of the distribution histogram 00173 // rnv: Customization of the vtkScalarBarActor to show distribution histogram: 00174 virtual int GetDistributionVisibility(); 00175 // Description: 00176 // Set distribution 00177 virtual void SetDistribution(std::vector<int> theNbValues); 00178 00179 // Description: 00180 // Set distribution coloring type (SMESH_MONOCOLOR_TYPE or SMESH_MULTICOLOR_TYPE) 00181 void SetDistributionColoringType(int theDistributionColoringType) {myDistributionColoringType = theDistributionColoringType;Modified();} 00182 00183 // Description: 00184 // Get distribution coloring type ((SMESH_MONOCOLOR_TYPE or SMESH_MULTICOLOR_TYPE)) 00185 int GetDistributionColoringType() {return myDistributionColoringType;} 00186 00187 // Description: 00188 // Set Distribution Color 00189 void SetDistributionColor (double rgb[3]); 00190 00191 // Description: 00192 // Get Distribution Color 00193 void GetDistributionColor (double rgb[3]); 00194 00195 00196 00197 protected: 00198 SMESH_ScalarBarActor(); 00199 ~SMESH_ScalarBarActor(); 00200 00201 vtkScalarsToColors *LookupTable; 00202 vtkTextProperty *TitleTextProperty; 00203 vtkTextProperty *LabelTextProperty; 00204 00205 int MaximumNumberOfColors; 00206 int NumberOfLabels; 00207 int NumberOfLabelsBuilt; 00208 int Orientation; 00209 char *Title; 00210 char *LabelFormat; 00211 00212 vtkTextMapper **TextMappers; 00213 virtual void AllocateAndSizeLabels(int *labelSize, int *size, 00214 vtkViewport *viewport, double *range); 00215 00216 00217 00218 private: 00219 vtkTextMapper *TitleMapper; 00220 vtkActor2D *TitleActor; 00221 00222 vtkActor2D **TextActors; 00223 00224 vtkPolyData *ScalarBar; 00225 vtkPolyDataMapper2D *ScalarBarMapper; 00226 vtkActor2D *ScalarBarActor; 00227 00228 vtkTimeStamp BuildTime; 00229 int LastSize[2]; 00230 int LastOrigin[2]; 00231 00232 void SizeTitle(int *titleSize, int *size, vtkViewport *viewport); 00233 00234 // rnv: Customization of the vtkScalarBarActor to show distribution histogram: 00235 vtkPolyData* myDistribution; //Distribution polygonal data 00236 vtkActor2D* myDistributionActor; //Distribution actor 00237 vtkPolyDataMapper2D* myDistributionMapper; //Distribution mapper 00238 std::vector<int> myNbValues; //Nb values for the range 00239 int myDistributionColoringType; //Distribution color type (monocolor or multicolor) 00240 00241 private: 00242 SMESH_ScalarBarActor(const SMESH_ScalarBarActor&); // Not implemented. 00243 void operator=(const SMESH_ScalarBarActor&); // Not implemented. 00244 }; 00245 00246 #endif //SMESH_SCALAR_BAR_ACTOR_H