1 | /*========================================================================= |
---|
2 | |
---|
3 | Program: Visualization Toolkit |
---|
4 | Module: vtkRpAxisActor2D.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 vtkRpAxisActor2D - Create an axis with tick marks and labels |
---|
16 | // .SECTION Description |
---|
17 | // vtkRpAxisActor2D creates an axis with tick marks, labels, and/or a title, |
---|
18 | // depending on the particular instance variable settings. vtkRpAxisActor2D is |
---|
19 | // a 2D actor; that is, it is drawn on the overlay plane and is not |
---|
20 | // occluded by 3D geometry. To use this class, you typically specify two |
---|
21 | // points defining the start and end points of the line (x-y definition using |
---|
22 | // vtkCoordinate class), the number of labels, and the data range |
---|
23 | // (min,max). You can also control what parts of the axis are visible |
---|
24 | // including the line, the tick marks, the labels, and the title. You can |
---|
25 | // also specify the label format (a printf style format). |
---|
26 | // |
---|
27 | // This class decides what font size to use and how to locate the labels. It |
---|
28 | // also decides how to create reasonable tick marks and labels. The number |
---|
29 | // of labels and the range of values may not match the number specified, but |
---|
30 | // should be close. |
---|
31 | // |
---|
32 | // Labels are drawn on the "right" side of the axis. The "right" side is |
---|
33 | // the side of the axis on the right as you move from Position to Position2. |
---|
34 | // The way the labels and title line up with the axis and tick marks depends on |
---|
35 | // whether the line is considered horizontal or vertical. |
---|
36 | // |
---|
37 | // The vtkActor2D instance variables Position and Position2 are instances of |
---|
38 | // vtkCoordinate. Note that the Position2 is an absolute position in that |
---|
39 | // class (it was by default relative to Position in vtkActor2D). |
---|
40 | // |
---|
41 | // What this means is that you can specify the axis in a variety of coordinate |
---|
42 | // systems. Also, the axis does not have to be either horizontal or vertical. |
---|
43 | // The tick marks are created so that they are perpendicular to the axis. |
---|
44 | // |
---|
45 | // Set the text property/attributes of the title and the labels through the |
---|
46 | // vtkTextProperty objects associated to this actor. |
---|
47 | // |
---|
48 | // .SECTION See Also |
---|
49 | // vtkCubeAxesActor2D can be used to create axes in world coordinate space. |
---|
50 | // |
---|
51 | // vtkActor2D vtkTextMapper vtkPolyDataMapper2D vtkScalarBarActor |
---|
52 | // vtkCoordinate vtkTextProperty |
---|
53 | |
---|
54 | #ifndef __vtkRpAxisActor2D_h |
---|
55 | #define __vtkRpAxisActor2D_h |
---|
56 | |
---|
57 | #include "vtkActor2D.h" |
---|
58 | |
---|
59 | class vtkPolyDataMapper2D; |
---|
60 | class vtkPolyData; |
---|
61 | class vtkTextMapper; |
---|
62 | class vtkTextProperty; |
---|
63 | |
---|
64 | #define VTK_MAX_LABELS 25 |
---|
65 | |
---|
66 | class VTK_RENDERING_EXPORT vtkRpAxisActor2D : public vtkActor2D |
---|
67 | { |
---|
68 | public: |
---|
69 | vtkTypeMacro(vtkRpAxisActor2D,vtkActor2D); |
---|
70 | void PrintSelf(ostream& os, vtkIndent indent); |
---|
71 | |
---|
72 | // Description: |
---|
73 | // Instantiate object. |
---|
74 | static vtkRpAxisActor2D *New(); |
---|
75 | |
---|
76 | // Description: |
---|
77 | // Specify the position of the first point defining the axis. |
---|
78 | // Note: backward compatibility only, use vtkActor2D's Position instead. |
---|
79 | virtual vtkCoordinate *GetPoint1Coordinate() |
---|
80 | { return this->GetPositionCoordinate(); }; |
---|
81 | virtual void SetPoint1(double x[2]) { this->SetPosition(x); }; |
---|
82 | virtual void SetPoint1(double x, double y) { this->SetPosition(x,y); }; |
---|
83 | virtual double *GetPoint1() { return this->GetPosition(); }; |
---|
84 | |
---|
85 | // Description: |
---|
86 | // Specify the position of the second point defining the axis. Note that |
---|
87 | // the order from Point1 to Point2 controls which side the tick marks |
---|
88 | // are drawn on (ticks are drawn on the right, if visible). |
---|
89 | // Note: backward compatibility only, use vtkActor2D's Position2 instead. |
---|
90 | virtual vtkCoordinate *GetPoint2Coordinate() |
---|
91 | { return this->GetPosition2Coordinate(); }; |
---|
92 | virtual void SetPoint2(double x[2]) { this->SetPosition2(x); }; |
---|
93 | virtual void SetPoint2(double x, double y) { this->SetPosition2(x,y); }; |
---|
94 | virtual double *GetPoint2() { return this->GetPosition2(); }; |
---|
95 | |
---|
96 | // Description: |
---|
97 | // Specify the (min,max) axis range. This will be used in the generation |
---|
98 | // of labels, if labels are visible. |
---|
99 | vtkSetVector2Macro(Range,double); |
---|
100 | vtkGetVectorMacro(Range,double,2); |
---|
101 | |
---|
102 | // Description: |
---|
103 | // Specify whether this axis should act like a measuring tape (or ruler) with |
---|
104 | // specified major tick spacing. If enabled, the distance between major ticks |
---|
105 | // is controlled by the RulerDistance ivar. |
---|
106 | vtkSetMacro(RulerMode,int); |
---|
107 | vtkGetMacro(RulerMode,int); |
---|
108 | vtkBooleanMacro(RulerMode,int); |
---|
109 | |
---|
110 | // Description: |
---|
111 | // Specify the RulerDistance which indicates the spacing of the major ticks. |
---|
112 | // This ivar only has effect when the RulerMode is on. |
---|
113 | vtkSetClampMacro(RulerDistance,double,0,VTK_LARGE_FLOAT); |
---|
114 | vtkGetMacro(RulerDistance,double); |
---|
115 | |
---|
116 | // Description: |
---|
117 | // Set/Get the number of annotation labels to show. This also controls the |
---|
118 | // number of major ticks shown. Note that this ivar only holds meaning if |
---|
119 | // the RulerMode is off. |
---|
120 | vtkSetClampMacro(NumberOfLabels, int, 2, VTK_MAX_LABELS); |
---|
121 | vtkGetMacro(NumberOfLabels, int); |
---|
122 | |
---|
123 | // Description: |
---|
124 | // Set/Get the format with which to print the labels on the scalar |
---|
125 | // bar. |
---|
126 | vtkSetStringMacro(LabelFormat); |
---|
127 | vtkGetStringMacro(LabelFormat); |
---|
128 | |
---|
129 | // Description: |
---|
130 | // Set/Get the flag that controls whether the labels and ticks are |
---|
131 | // adjusted for "nice" numerical values to make it easier to read |
---|
132 | // the labels. The adjustment is based in the Range instance variable. |
---|
133 | // Call GetAdjustedRange and GetAdjustedNumberOfLabels to get the adjusted |
---|
134 | // range and number of labels. Note that if RulerMode is on, then the |
---|
135 | // number of labels is a function of the range and ruler distance. |
---|
136 | vtkSetMacro(AdjustLabels, int); |
---|
137 | vtkGetMacro(AdjustLabels, int); |
---|
138 | vtkBooleanMacro(AdjustLabels, int); |
---|
139 | virtual double *GetAdjustedRange() |
---|
140 | { |
---|
141 | this->UpdateAdjustedRange(); |
---|
142 | return this->AdjustedRange; |
---|
143 | } |
---|
144 | virtual void GetAdjustedRange(double &_arg1, double &_arg2) |
---|
145 | { |
---|
146 | this->UpdateAdjustedRange(); |
---|
147 | _arg1 = this->AdjustedRange[0]; |
---|
148 | _arg2 = this->AdjustedRange[1]; |
---|
149 | }; |
---|
150 | virtual void GetAdjustedRange(double _arg[2]) |
---|
151 | { |
---|
152 | this->GetAdjustedRange(_arg[0], _arg[1]); |
---|
153 | } |
---|
154 | virtual int GetAdjustedNumberOfLabels() |
---|
155 | { |
---|
156 | this->UpdateAdjustedRange(); |
---|
157 | return this->AdjustedNumberOfLabels; |
---|
158 | } |
---|
159 | |
---|
160 | // Description: |
---|
161 | // Set/Get the title of the scalar bar actor, |
---|
162 | vtkSetStringMacro(Title); |
---|
163 | vtkGetStringMacro(Title); |
---|
164 | |
---|
165 | // Description: |
---|
166 | // Set/Get the title text property. |
---|
167 | virtual void SetTitleTextProperty(vtkTextProperty *p); |
---|
168 | vtkGetObjectMacro(TitleTextProperty,vtkTextProperty); |
---|
169 | |
---|
170 | // Description: |
---|
171 | // Set/Get the labels text property. |
---|
172 | virtual void SetLabelTextProperty(vtkTextProperty *p); |
---|
173 | vtkGetObjectMacro(LabelTextProperty,vtkTextProperty); |
---|
174 | |
---|
175 | // Description: |
---|
176 | // Set/Get the length of the tick marks (expressed in pixels or display |
---|
177 | // coordinates). |
---|
178 | vtkSetClampMacro(TickLength, int, 0, 100); |
---|
179 | vtkGetMacro(TickLength, int); |
---|
180 | |
---|
181 | // Description: |
---|
182 | // Number of minor ticks to be displayed between each tick. Default |
---|
183 | // is 0. |
---|
184 | vtkSetClampMacro(NumberOfMinorTicks, int, 0, 20); |
---|
185 | vtkGetMacro(NumberOfMinorTicks, int); |
---|
186 | |
---|
187 | // Description: |
---|
188 | // Set/Get the length of the minor tick marks (expressed in pixels or |
---|
189 | // display coordinates). |
---|
190 | vtkSetClampMacro(MinorTickLength, int, 0, 100); |
---|
191 | vtkGetMacro(MinorTickLength, int); |
---|
192 | |
---|
193 | // Description: |
---|
194 | // Set/Get the offset of the labels (expressed in pixels or display |
---|
195 | // coordinates). The offset is the distance of labels from tick marks |
---|
196 | // or other objects. |
---|
197 | vtkSetClampMacro(TickOffset, int, 0, 100); |
---|
198 | vtkGetMacro(TickOffset, int); |
---|
199 | |
---|
200 | // Description: |
---|
201 | // Set/Get visibility of the axis line. |
---|
202 | vtkSetMacro(AxisVisibility, int); |
---|
203 | vtkGetMacro(AxisVisibility, int); |
---|
204 | vtkBooleanMacro(AxisVisibility, int); |
---|
205 | |
---|
206 | // Description: |
---|
207 | // Set/Get visibility of the axis tick marks. |
---|
208 | vtkSetMacro(TickVisibility, int); |
---|
209 | vtkGetMacro(TickVisibility, int); |
---|
210 | vtkBooleanMacro(TickVisibility, int); |
---|
211 | |
---|
212 | // Description: |
---|
213 | // Set/Get visibility of the axis labels. |
---|
214 | vtkSetMacro(LabelVisibility, int); |
---|
215 | vtkGetMacro(LabelVisibility, int); |
---|
216 | vtkBooleanMacro(LabelVisibility, int); |
---|
217 | |
---|
218 | // Description: |
---|
219 | // Set/Get visibility of the axis title. |
---|
220 | vtkSetMacro(TitleVisibility, int); |
---|
221 | vtkGetMacro(TitleVisibility, int); |
---|
222 | vtkBooleanMacro(TitleVisibility, int); |
---|
223 | |
---|
224 | // Description: |
---|
225 | // Set/Get position of the axis title. 0 is at the start of the |
---|
226 | // axis whereas 1 is at the end. |
---|
227 | vtkSetMacro(TitlePosition, double); |
---|
228 | vtkGetMacro(TitlePosition, double); |
---|
229 | |
---|
230 | // Description: |
---|
231 | // Set/Get the factor that controls the overall size of the fonts used |
---|
232 | // to label and title the axes. This ivar used in conjunction with |
---|
233 | // the LabelFactor can be used to control font sizes. |
---|
234 | vtkSetClampMacro(FontFactor, double, 0.1, 2.0); |
---|
235 | vtkGetMacro(FontFactor, double); |
---|
236 | |
---|
237 | // Description: |
---|
238 | // Set/Get the factor that controls the relative size of the axis labels |
---|
239 | // to the axis title. |
---|
240 | vtkSetClampMacro(LabelFactor, double, 0.1, 2.0); |
---|
241 | vtkGetMacro(LabelFactor, double); |
---|
242 | |
---|
243 | // Description: |
---|
244 | // Draw the axis. |
---|
245 | int RenderOverlay(vtkViewport* viewport); |
---|
246 | int RenderOpaqueGeometry(vtkViewport* viewport); |
---|
247 | virtual int RenderTranslucentPolygonalGeometry(vtkViewport *) {return 0;} |
---|
248 | |
---|
249 | // Description: |
---|
250 | // Does this prop have some translucent polygonal geometry? |
---|
251 | virtual int HasTranslucentPolygonalGeometry(); |
---|
252 | |
---|
253 | // Description: |
---|
254 | // Release any graphics resources that are being consumed by this actor. |
---|
255 | // The parameter window could be used to determine which graphic |
---|
256 | // resources to release. |
---|
257 | void ReleaseGraphicsResources(vtkWindow *); |
---|
258 | |
---|
259 | // Description: |
---|
260 | // This method computes the range of the axis given an input range. |
---|
261 | // It also computes the number of tick marks given a suggested number. |
---|
262 | // (The number of tick marks includes end ticks as well.) |
---|
263 | // The number of tick marks computed (in conjunction with the output |
---|
264 | // range) will yield "nice" tick values. For example, if the input range |
---|
265 | // is (0.25,96.7) and the number of ticks requested is 10, the output range |
---|
266 | // will be (0,100) with the number of computed ticks to 11 to yield tick |
---|
267 | // values of (0,10,20,...,100). |
---|
268 | static void ComputeRange(double inRange[2], |
---|
269 | double outRange[2], |
---|
270 | int inNumTicks, |
---|
271 | int &outNumTicks, |
---|
272 | double &interval); |
---|
273 | |
---|
274 | // Description: |
---|
275 | // General method to computes font size from a representative size on the |
---|
276 | // viewport (given by size[2]). The method returns the font size (in points) |
---|
277 | // and the string height/width (in pixels). It also sets the font size of the |
---|
278 | // instance of vtkTextMapper provided. The factor is used when you're trying |
---|
279 | // to create text of different size-factor (it is usually = 1 but you can |
---|
280 | // adjust the font size by making factor larger or smaller). |
---|
281 | static int SetMultipleFontSize(vtkViewport *viewport, |
---|
282 | vtkTextMapper **textMappers, |
---|
283 | int nbOfMappers, |
---|
284 | int *targetSize, |
---|
285 | double factor, |
---|
286 | int *stringSize); |
---|
287 | |
---|
288 | // Description: |
---|
289 | // Specify whether to size the fonts relative to the viewport or relative to |
---|
290 | // length of the axis. By default, fonts are resized relative to the axis. |
---|
291 | vtkSetMacro(SizeFontRelativeToAxis,int); |
---|
292 | vtkGetMacro(SizeFontRelativeToAxis,int); |
---|
293 | vtkBooleanMacro(SizeFontRelativeToAxis,int); |
---|
294 | |
---|
295 | // Description: |
---|
296 | // Shallow copy of an axis actor. Overloads the virtual vtkProp method. |
---|
297 | void ShallowCopy(vtkProp *prop); |
---|
298 | |
---|
299 | protected: |
---|
300 | vtkRpAxisActor2D(); |
---|
301 | ~vtkRpAxisActor2D(); |
---|
302 | |
---|
303 | vtkTextProperty *TitleTextProperty; |
---|
304 | vtkTextProperty *LabelTextProperty; |
---|
305 | |
---|
306 | char *Title; |
---|
307 | double Range[2]; |
---|
308 | double TitlePosition; |
---|
309 | int RulerMode; |
---|
310 | double RulerDistance; |
---|
311 | int NumberOfLabels; |
---|
312 | char *LabelFormat; |
---|
313 | int AdjustLabels; |
---|
314 | double FontFactor; |
---|
315 | double LabelFactor; |
---|
316 | int TickLength; |
---|
317 | int MinorTickLength; |
---|
318 | int TickOffset; |
---|
319 | int NumberOfMinorTicks; |
---|
320 | |
---|
321 | double AdjustedRange[2]; |
---|
322 | int AdjustedNumberOfLabels; |
---|
323 | int NumberOfLabelsBuilt; |
---|
324 | |
---|
325 | int AxisVisibility; |
---|
326 | int TickVisibility; |
---|
327 | int LabelVisibility; |
---|
328 | int TitleVisibility; |
---|
329 | |
---|
330 | int LastPosition[2]; |
---|
331 | int LastPosition2[2]; |
---|
332 | |
---|
333 | int LastSize[2]; |
---|
334 | int LastMaxLabelSize[2]; |
---|
335 | |
---|
336 | int SizeFontRelativeToAxis; |
---|
337 | |
---|
338 | virtual void BuildAxis(vtkViewport *viewport); |
---|
339 | static double ComputeStringOffset(double width, double height, double theta); |
---|
340 | static void SetOffsetPosition(double xTick[3], double theta, |
---|
341 | int stringHeight, int stringWidth, |
---|
342 | int offset, vtkActor2D *actor); |
---|
343 | virtual void UpdateAdjustedRange(); |
---|
344 | |
---|
345 | vtkTextMapper *TitleMapper; |
---|
346 | vtkActor2D *TitleActor; |
---|
347 | |
---|
348 | vtkTextMapper **LabelMappers; |
---|
349 | vtkActor2D **LabelActors; |
---|
350 | |
---|
351 | vtkPolyData *Axis; |
---|
352 | vtkPolyDataMapper2D *AxisMapper; |
---|
353 | vtkActor2D *AxisActor; |
---|
354 | |
---|
355 | vtkTimeStamp AdjustedRangeBuildTime; |
---|
356 | vtkTimeStamp BuildTime; |
---|
357 | |
---|
358 | private: |
---|
359 | vtkRpAxisActor2D(const vtkRpAxisActor2D&); // Not implemented. |
---|
360 | void operator=(const vtkRpAxisActor2D&); // Not implemented. |
---|
361 | }; |
---|
362 | |
---|
363 | |
---|
364 | #endif |
---|