1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkLegendScaleActor.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 // .NAME vtkLegendScaleActor - annotate the render window with scale and distance information 16 // .SECTION Description 17 // This class is used to annotate the render window. Its basic goal is to 18 // provide an indication of the scale of the scene. Four axes surrounding the 19 // render window indicate (in a variety of ways) the scale of what the camera 20 // is viewing. An option also exists for displaying a scale legend. 21 // 22 // The axes can be programmed either to display distance scales or x-y 23 // coordinate values. By default, the scales display a distance. However, 24 // if you know that the view is down the z-axis, the scales can be programmed 25 // to display x-y coordinate values. 26 // 27 // .SECTION Caveats 28 // Please be aware that the axes and scale values are subject to perspective 29 // effects. The distances are computed in the focal plane of the camera. 30 // When there are large view angles (i.e., perspective projection), the 31 // computed distances may provide users the wrong sense of scale. These 32 // effects are not present when parallel projection is enabled. 33 34 #ifndef vtkLegendScaleActor_h 35 #define vtkLegendScaleActor_h 36 37 #include "vtkRenderingAnnotationModule.h" // For export macro 38 #include "vtkProp.h" 39 #include "vtkCoordinate.h" // For vtkViewportCoordinateMacro 40 41 class vtkAxisActor2D; 42 class vtkTextProperty; 43 class vtkPolyData; 44 class vtkPolyDataMapper2D; 45 class vtkActor2D; 46 class vtkTextMapper; 47 class vtkPoints; 48 class vtkCoordinate; 49 50 class VTKRENDERINGANNOTATION_EXPORT vtkLegendScaleActor : public vtkProp 51 { 52 public: 53 // Description: 54 // Instantiate the class. 55 static vtkLegendScaleActor *New(); 56 57 // Description: 58 // Standard methods for the class. 59 vtkTypeMacro(vtkLegendScaleActor,vtkProp); 60 void PrintSelf(ostream& os, vtkIndent indent); 61 62 //BTX 63 enum AttributeLocation 64 { 65 DISTANCE=0, 66 XY_COORDINATES=1 67 }; 68 //ETX 69 70 // Description: 71 // Specify the mode for labeling the scale axes. By default, the axes are 72 // labeled with the distance between points (centered at a distance of 73 // 0.0). Alternatively if you know that the view is down the z-axis; the 74 // axes can be labeled with x-y coordinate values. 75 vtkSetClampMacro(LabelMode,int,DISTANCE,XY_COORDINATES); 76 vtkGetMacro(LabelMode,int); SetLabelModeToDistance()77 void SetLabelModeToDistance() {this->SetLabelMode(DISTANCE);} SetLabelModeToXYCoordinates()78 void SetLabelModeToXYCoordinates() {this->SetLabelMode(XY_COORDINATES);} 79 80 // Description: 81 // Set/Get the flags that control which of the four axes to display (top, 82 // bottom, left and right). By default, all the axes are displayed. 83 vtkSetMacro(RightAxisVisibility,int); 84 vtkGetMacro(RightAxisVisibility,int); 85 vtkBooleanMacro(RightAxisVisibility,int); 86 vtkSetMacro(TopAxisVisibility,int); 87 vtkGetMacro(TopAxisVisibility,int); 88 vtkBooleanMacro(TopAxisVisibility,int); 89 vtkSetMacro(LeftAxisVisibility,int); 90 vtkGetMacro(LeftAxisVisibility,int); 91 vtkBooleanMacro(LeftAxisVisibility,int); 92 vtkSetMacro(BottomAxisVisibility,int); 93 vtkGetMacro(BottomAxisVisibility,int); 94 vtkBooleanMacro(BottomAxisVisibility,int); 95 96 // Description: 97 // Indicate whether the legend scale should be displayed or not. 98 // The default is On. 99 vtkSetMacro(LegendVisibility,int); 100 vtkGetMacro(LegendVisibility,int); 101 vtkBooleanMacro(LegendVisibility,int); 102 103 // Description: 104 // Convenience method that turns all the axes either on or off. 105 void AllAxesOn(); 106 void AllAxesOff(); 107 108 // Description: 109 // Convenience method that turns all the axes and the legend scale. 110 void AllAnnotationsOn(); 111 void AllAnnotationsOff(); 112 113 // Description: 114 // Set/Get the offset of the right axis from the border. This number is expressed in 115 // pixels, and represents the approximate distance of the axes from the sides 116 // of the renderer. The default is 50. 117 vtkSetClampMacro(RightBorderOffset,int,5,VTK_INT_MAX); 118 vtkGetMacro(RightBorderOffset,int); 119 120 // Description: 121 // Set/Get the offset of the top axis from the border. This number is expressed in 122 // pixels, and represents the approximate distance of the axes from the sides 123 // of the renderer. The default is 30. 124 vtkSetClampMacro(TopBorderOffset,int,5,VTK_INT_MAX); 125 vtkGetMacro(TopBorderOffset,int); 126 127 // Description: 128 // Set/Get the offset of the left axis from the border. This number is expressed in 129 // pixels, and represents the approximate distance of the axes from the sides 130 // of the renderer. The default is 50. 131 vtkSetClampMacro(LeftBorderOffset,int,5,VTK_INT_MAX); 132 vtkGetMacro(LeftBorderOffset,int); 133 134 // Description: 135 // Set/Get the offset of the bottom axis from the border. This number is expressed in 136 // pixels, and represents the approximate distance of the axes from the sides 137 // of the renderer. The default is 30. 138 vtkSetClampMacro(BottomBorderOffset,int,5,VTK_INT_MAX); 139 vtkGetMacro(BottomBorderOffset,int); 140 141 // Description: 142 // Get/Set the corner offset. This is the offset factor used to offset the 143 // axes at the corners. Default value is 2.0. 144 vtkSetClampMacro(CornerOffsetFactor, double, 1.0, 10.0); 145 vtkGetMacro(CornerOffsetFactor, double); 146 147 // Description: 148 // Set/Get the labels text properties for the legend title and labels. 149 vtkGetObjectMacro(LegendTitleProperty,vtkTextProperty); 150 vtkGetObjectMacro(LegendLabelProperty,vtkTextProperty); 151 152 // Description: 153 // These are methods to retrieve the vtkAxisActors used to represent 154 // the four axes that form this representation. Users may retrieve and 155 // then modify these axes to control their appearance. 156 vtkGetObjectMacro(RightAxis,vtkAxisActor2D); 157 vtkGetObjectMacro(TopAxis,vtkAxisActor2D); 158 vtkGetObjectMacro(LeftAxis,vtkAxisActor2D); 159 vtkGetObjectMacro(BottomAxis,vtkAxisActor2D); 160 161 // Decsription: 162 // Standard methods supporting the rendering process. 163 virtual void BuildRepresentation(vtkViewport *viewport); 164 virtual void GetActors2D(vtkPropCollection*); 165 virtual void ReleaseGraphicsResources(vtkWindow*); 166 virtual int RenderOverlay(vtkViewport*); 167 virtual int RenderOpaqueGeometry(vtkViewport*); 168 169 protected: 170 vtkLegendScaleActor(); 171 ~vtkLegendScaleActor(); 172 173 int LabelMode; 174 int RightBorderOffset; 175 int TopBorderOffset; 176 int LeftBorderOffset; 177 int BottomBorderOffset; 178 double CornerOffsetFactor; 179 180 // The four axes around the borders of the renderer 181 vtkAxisActor2D *RightAxis; 182 vtkAxisActor2D *TopAxis; 183 vtkAxisActor2D *LeftAxis; 184 vtkAxisActor2D *BottomAxis; 185 186 // Control the display of the axes 187 int RightAxisVisibility; 188 int TopAxisVisibility; 189 int LeftAxisVisibility; 190 int BottomAxisVisibility; 191 192 // Support for the legend. 193 int LegendVisibility; 194 vtkPolyData *Legend; 195 vtkPoints *LegendPoints; 196 vtkPolyDataMapper2D *LegendMapper; 197 vtkActor2D *LegendActor; 198 vtkTextMapper *LabelMappers[6]; 199 vtkActor2D *LabelActors[6]; 200 vtkTextProperty *LegendTitleProperty; 201 vtkTextProperty *LegendLabelProperty; 202 vtkCoordinate *Coordinate; 203 204 vtkTimeStamp BuildTime; 205 206 private: 207 vtkLegendScaleActor(const vtkLegendScaleActor&); //Not implemented 208 void operator=(const vtkLegendScaleActor&); //Not implemented 209 }; 210 211 #endif 212