source: trunk/packages/vizservers/vtkvis/vtkRpAxisActor.h @ 3132

Last change on this file since 3132 was 2864, checked in by ldelgass, 12 years ago

Include custom version of VTK 3d axes, with fix for showing gridlines only on
active axis planes. Also include a copy of 2D/3D axis classes, though these
are not currently customized. Based on VTK 5.8.0.

  • Property svn:eol-style set to native
File size: 12.2 KB
Line 
1/*=========================================================================
2
3  Program:   Visualization Toolkit
4  Module:    vtkRpAxisActor.h
5  Language:  C++
6  Date:      $Date$
7  Version:   $Revision$
8  Thanks:    Kathleen Bonnell, B Division, Lawrence Livermore Nat'l Laboratory
9
10Copyright (c) 1993-2000 Ken Martin, Will Schroeder, Bill Lorensen
11All rights reserved.
12     This software is distributed WITHOUT ANY WARRANTY; without even
13     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14     PURPOSE.  See the above copyright notice for more information.
15=========================================================================*/
16// .NAME vtkRpAxisActor - Create an axis with tick marks and labels
17// .SECTION Description
18// vtkRpAxisActor creates an axis with tick marks, labels, and/or a title,
19// depending on the particular instance variable settings. It is assumed that
20// the axes is part of a bounding box and is orthoganal to one of the
21// coordinate axes.  To use this class, you typically specify two points
22// defining the start and end points of the line (xyz definition using
23// vtkCoordinate class), the axis type (X, Y or Z), the axis location in
24// relation to the bounding box, the bounding box, the number of labels, and
25// the data range (min,max). You can also control what parts of the axis are
26// visible including the line, the tick marks, the labels, and the title. It
27// is also possible to control gridlines, and specifiy on which 'side' the
28// tickmarks are drawn (again with respect to the underlying assumed
29// bounding box). You can also specify the label format (a printf style format).
30//
31// This class decides how to locate the labels, and how to create reasonable
32// tick marks and labels.
33//
34// Labels follow the camera so as to be legible from any viewpoint.
35//
36// The instance variables Point1 and Point2 are instances of vtkCoordinate.
37// All calculations and references are in World Coordinates.
38//
39// .SECTION Notes
40// This class was adapted from a 2D version created by Hank Childs called
41// vtkHankAxisActor2D.
42//
43// .SECTION See Also
44// vtkActor vtkVectorText vtkPolyDataMapper vtkRpAxisActor2D vtkCoordinate
45
46#ifndef __vtkRpAxisActor_h
47#define __vtkRpAxisActor_h
48
49#include "vtkActor.h"
50
51#define VTK_MAX_LABELS    200
52#define VTK_MAX_TICKS     1000
53
54#define VTK_AXIS_TYPE_X   0
55#define VTK_AXIS_TYPE_Y   1
56#define VTK_AXIS_TYPE_Z   2
57
58#define VTK_TICKS_INSIDE  0
59#define VTK_TICKS_OUTSIDE 1
60#define VTK_TICKS_BOTH    2
61
62#define VTK_AXIS_POS_MINMIN 0
63#define VTK_AXIS_POS_MINMAX 1
64#define VTK_AXIS_POS_MAXMAX 2
65#define VTK_AXIS_POS_MAXMIN 3
66
67// ****************************************************************************
68//  Modifications:
69//    Kathleen Bonnell, Tue Aug 31 16:17:43 PDT 2004
70//    Added TitleTextTime timestamp, so that title can be updated appropriately
71//    when its text changes.  Changed Titles Set macro for a user-defined
72//    set so TitleTextTime can be updated.
73//
74// ****************************************************************************
75
76class vtkCamera;
77class vtkCoordinate;
78class vtkFollower;
79class vtkPoints;
80class vtkPolyData;
81class vtkPolyDataMapper;
82class vtkStringArray;
83class vtkVectorText;
84
85class VTK_HYBRID_EXPORT vtkRpAxisActor : public vtkActor
86{
87public:
88  vtkTypeMacro(vtkRpAxisActor,vtkActor);
89  void PrintSelf(ostream& os, vtkIndent indent);
90
91  // Description:
92  // Instantiate object.
93  static vtkRpAxisActor *New();
94
95  // Description:
96  // Specify the position of the first point defining the axis.
97  virtual vtkCoordinate *GetPoint1Coordinate();
98  virtual void SetPoint1(double x[3])
99    { this->SetPoint1(x[0], x[1], x[2]); }
100  virtual void SetPoint1(double x, double y, double z);
101  virtual double *GetPoint1();
102
103  // Description:
104  // Specify the position of the second point defining the axis.
105  virtual vtkCoordinate *GetPoint2Coordinate();
106  virtual void SetPoint2(double x[3])
107    { this->SetPoint2(x[0], x[1], x[2]); }
108  virtual void SetPoint2(double x, double y, double z);
109  virtual double *GetPoint2();
110
111  // Description:
112  // Specify the (min,max) axis range. This will be used in the generation
113  // of labels, if labels are visible.
114  vtkSetVector2Macro(Range,double);
115  vtkGetVectorMacro(Range,double,2);
116
117  // Description:
118  // Set or get the bounds for this Actor as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
119  void   SetBounds(double bounds[6]);
120  void   SetBounds(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax);
121  double *GetBounds(void);
122  void   GetBounds(double bounds[6]);
123
124  // Description:
125  // Set/Get the format with which to print the labels on the axis.
126  vtkSetStringMacro(LabelFormat);
127  vtkGetStringMacro(LabelFormat);
128
129  // Description:
130  // Set/Get the flag that controls whether the minor ticks are visible.
131  vtkSetMacro(MinorTicksVisible, int);
132  vtkGetMacro(MinorTicksVisible, int);
133  vtkBooleanMacro(MinorTicksVisible, int);
134
135
136  // Description:
137  // Set/Get the title of the axis actor,
138  void SetTitle(const char *t);
139  vtkGetStringMacro(Title);
140
141  // Description:
142  // Set/Get the size of the major tick marks
143  vtkSetMacro(MajorTickSize, double);
144  vtkGetMacro(MajorTickSize, double);
145
146  // Description:
147  // Set/Get the size of the major tick marks
148  vtkSetMacro(MinorTickSize, double);
149  vtkGetMacro(MinorTickSize, double);
150
151  // Description:
152  // Set/Get the location of the ticks.
153  vtkSetClampMacro(TickLocation, int, VTK_TICKS_INSIDE, VTK_TICKS_BOTH);
154  vtkGetMacro(TickLocation, int);
155
156  void SetTickLocationToInside(void)
157    { this->SetTickLocation(VTK_TICKS_INSIDE); };
158  void SetTickLocationToOutside(void)
159    { this->SetTickLocation(VTK_TICKS_OUTSIDE); };
160  void SetTickLocationToBoth(void)
161    { this->SetTickLocation(VTK_TICKS_BOTH); };
162
163  // Description:
164  // Set/Get visibility of the axis line.
165  vtkSetMacro(AxisVisibility, int);
166  vtkGetMacro(AxisVisibility, int);
167  vtkBooleanMacro(AxisVisibility, int);
168
169  // Description:
170  // Set/Get visibility of the axis tick marks.
171  vtkSetMacro(TickVisibility, int);
172  vtkGetMacro(TickVisibility, int);
173  vtkBooleanMacro(TickVisibility, int);
174
175  // Description:
176  // Set/Get visibility of the axis labels.
177  vtkSetMacro(LabelVisibility, int);
178  vtkGetMacro(LabelVisibility, int);
179  vtkBooleanMacro(LabelVisibility, int);
180
181  // Description:
182  // Set/Get visibility of the axis title.
183  vtkSetMacro(TitleVisibility, int);
184  vtkGetMacro(TitleVisibility, int);
185  vtkBooleanMacro(TitleVisibility, int);
186
187  // Description:
188  // Set/Get whether gridlines should be drawn.
189  vtkSetMacro(DrawGridlines, int);
190  vtkGetMacro(DrawGridlines, int);
191  vtkBooleanMacro(DrawGridlines, int);
192
193  // Description:
194  // Set/Get the length to use when drawing gridlines.
195  vtkSetMacro(GridlineXLength, double);
196  vtkGetMacro(GridlineXLength, double);
197  vtkSetMacro(GridlineYLength, double);
198  vtkGetMacro(GridlineYLength, double);
199  vtkSetMacro(GridlineZLength, double);
200  vtkGetMacro(GridlineZLength, double);
201
202  // Description:
203  // Set/Get the type of this axis.
204  vtkSetClampMacro(AxisType, int, VTK_AXIS_TYPE_X, VTK_AXIS_TYPE_Z);
205  vtkGetMacro(AxisType, int);
206  void SetAxisTypeToX(void) { this->SetAxisType(VTK_AXIS_TYPE_X); };
207  void SetAxisTypeToY(void) { this->SetAxisType(VTK_AXIS_TYPE_Y); };
208  void SetAxisTypeToZ(void) { this->SetAxisType(VTK_AXIS_TYPE_Z); };
209
210  // Description:
211  // Set/Get the position of this axis (in relation to an an
212  // assumed bounding box).  For an x-type axis, MINMIN corresponds
213  // to the x-edge in the bounding box where Y values are minimum and
214  // Z values are minimum. For a y-type axis, MAXMIN corresponds to the
215  // y-edge where X values are maximum and Z values are minimum.
216  //
217  vtkSetClampMacro(AxisPosition, int, VTK_AXIS_POS_MINMIN, VTK_AXIS_POS_MAXMIN);
218  vtkGetMacro(AxisPosition, int);
219
220  void SetAxisPositionToMinMin(void)
221      { this->SetAxisPosition(VTK_AXIS_POS_MINMIN); };
222  void SetAxisPositionToMinMax(void)
223      { this->SetAxisPosition(VTK_AXIS_POS_MINMAX); };
224  void SetAxisPositionToMaxMax(void)
225      { this->SetAxisPosition(VTK_AXIS_POS_MAXMAX); };
226  void SetAxisPositionToMaxMin(void)
227      { this->SetAxisPosition(VTK_AXIS_POS_MAXMIN); };
228
229  // Description:
230  // Set/Get the camera for this axis.  The camera is used by the
231  // labels to 'follow' the camera and be legible from any viewpoint.
232  virtual void SetCamera(vtkCamera*);
233  vtkGetObjectMacro(Camera, vtkCamera);
234
235  // Description:
236  // Draw the axis.
237  virtual int RenderOpaqueGeometry(vtkViewport* viewport);
238  virtual int RenderTranslucentGeometry(vtkViewport *) {return 0;}
239
240  // Description:
241  // Release any graphics resources that are being consumed by this actor.
242  // The parameter window could be used to determine which graphic
243  // resources to release.
244  void ReleaseGraphicsResources(vtkWindow *);
245
246  // Description:
247  // Shallow copy of an axis actor. Overloads the virtual vtkProp method.
248  void ShallowCopy(vtkProp *prop);
249
250//BTX
251  double ComputeMaxLabelLength(const double [3]);
252  double ComputeTitleLength(const double [3]);
253//ETX
254  void SetLabelScale(const double);
255  void SetTitleScale(const double);
256
257
258  // Description:
259  // Set/Get the starting position for minor and major tick points,
260  // and the delta values that determine their spacing.
261  vtkSetMacro(MinorStart, double);
262  vtkGetMacro(MinorStart, double);
263  vtkSetMacro(MajorStart, double);
264  vtkGetMacro(MajorStart, double);
265  vtkSetMacro(DeltaMinor, double);
266  vtkGetMacro(DeltaMinor, double);
267  vtkSetMacro(DeltaMajor, double);
268  vtkGetMacro(DeltaMajor, double);
269
270  // Description:
271  // Set/Get the starting position for minor and major tick points on
272  // the range and the delta values that determine their spacing. The
273  // range and the position need not be identical. ie the displayed
274  // values need not match the actual positions in 3D space.
275  vtkSetMacro(MinorRangeStart, double);
276  vtkGetMacro(MinorRangeStart, double);
277  vtkSetMacro(MajorRangeStart, double);
278  vtkGetMacro(MajorRangeStart, double);
279  vtkSetMacro(DeltaRangeMinor, double);
280  vtkGetMacro(DeltaRangeMinor, double);
281  vtkSetMacro(DeltaRangeMajor, double);
282  vtkGetMacro(DeltaRangeMajor, double);
283
284//BTX
285  void SetLabels(vtkStringArray *labels);
286//ETX
287
288  void BuildAxis(vtkViewport *viewport, bool);
289
290protected:
291  vtkRpAxisActor();
292  ~vtkRpAxisActor();
293
294  char  *Title;
295  double  Range[2];
296  double  LastRange[2];
297  char  *LabelFormat;
298  int    NumberOfLabelsBuilt;
299  int    MinorTicksVisible;
300  int    LastMinorTicksVisible;
301  int    TickLocation;
302
303  int    DrawGridlines;
304  int    LastDrawGridlines;
305  double  GridlineXLength;
306  double  GridlineYLength;
307  double  GridlineZLength;
308
309  int    AxisVisibility;
310  int    TickVisibility;
311  int    LastTickVisibility;
312  int    LabelVisibility;
313  int    TitleVisibility;
314
315  int    AxisType;
316  int    AxisPosition;
317  double  Bounds[6];
318
319private:
320  vtkRpAxisActor(const vtkRpAxisActor&); // Not implemented
321  void operator=(const vtkRpAxisActor&); // Not implemented
322
323  void TransformBounds(vtkViewport *, double bnds[6]);
324
325  void BuildLabels(vtkViewport *, bool);
326  void SetLabelPositions(vtkViewport *, bool);
327
328  void BuildTitle(bool);
329
330  void SetAxisPointsAndLines(void);
331  bool BuildTickPointsForXType(double p1[3], double p2[3], bool);
332  bool BuildTickPointsForYType(double p1[3], double p2[3], bool);
333  bool BuildTickPointsForZType(double p1[3], double p2[3], bool);
334
335  bool TickVisibilityChanged(void);
336
337  vtkCoordinate *Point1Coordinate;
338  vtkCoordinate *Point2Coordinate;
339
340  double  MajorTickSize;
341  double  MinorTickSize;
342
343  // for the positions
344  double  MajorStart;
345  double  MinorStart;
346
347  double  DeltaMinor;
348  double  DeltaMajor;
349
350  // For the ticks, w.r.t to the set range
351  double  MajorRangeStart;
352  double  MinorRangeStart;
353  double  DeltaRangeMinor;
354  double  DeltaRangeMajor;
355
356  int    LastAxisPosition;
357  int    LastAxisType;
358  int    LastTickLocation;
359  double  LastLabelStart;
360
361  vtkPoints         *MinorTickPts;
362  vtkPoints         *MajorTickPts;
363  vtkPoints         *GridlinePts;
364
365  vtkVectorText     *TitleVector;
366  vtkPolyDataMapper *TitleMapper;
367  vtkFollower       *TitleActor;
368
369  vtkVectorText     **LabelVectors;
370  vtkPolyDataMapper **LabelMappers;
371  vtkFollower       **LabelActors;
372
373  vtkPolyData        *Axis;
374  vtkPolyDataMapper  *AxisMapper;
375  vtkActor           *AxisActor;
376
377  vtkCamera          *Camera;
378  vtkTimeStamp        BuildTime;
379  vtkTimeStamp        BoundsTime;
380  vtkTimeStamp        LabelBuildTime;
381  vtkTimeStamp        TitleTextTime;
382
383  int                 AxisHasZeroLength;
384};
385
386
387#endif
Note: See TracBrowser for help on using the repository browser.