source: vtkvis/trunk/vtkRpAxisActor.h @ 4635

Last change on this file since 4635 was 3549, checked in by ldelgass, 11 years ago

Fix for oversized axis labels. AutoScale? computation in CubeAxesActor? happens
before label positions may be rebuilt (when rendering each AxisActor?), so
recompute AutoScale? in AxisActor? when rebuilding the axis.

  • Property svn:eol-style set to native
File size: 18.8 KB
Line 
1/*=========================================================================
2
3Program:   Visualization Toolkit
4Module:    vtkRpAxisActor.h
5Language:  C++
6Date:      $Date$
7Version:   $Revision$
8Thanks:    Kathleen Bonnell, B Division, Lawrence Livermore Nat'l Laboratory
9
10Copyright (c) 1993-2000 Ken Martin, Will Schroeder, Bill Lorensen
11All rights reserved.
12This software is distributed WITHOUT ANY WARRANTY; without even
13the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14PURPOSE.  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 Thanks
40// This class was written by:
41// Hank Childs, Kathleen Bonnell, Amy Squillacote, Brad Whitlock,
42// Eric Brugger, Claire Guilbaud, Nicolas Dolegieviez, Will Schroeder,
43// Karthik Krishnan, Aashish Chaudhary, Philippe Pebay, David Gobbi,
44// David Partyka, Utkarsh Ayachit David Cole, Francois Bertel, and Mark Olesen
45// Part of this work was supported by CEA/DIF - Commissariat a l'Energie Atomique,
46// Centre DAM Ile-De-France, BP12, F-91297 Arpajon, France.
47//
48// .SECTION See Also
49// vtkActor vtkVectorText vtkPolyDataMapper vtkRpAxisActor2D vtkCoordinate
50
51#ifndef __vtkRpAxisActor_h
52#define __vtkRpAxisActor_h
53
54#include "vtkRenderingAnnotationModule.h" // For export macro
55#include "vtkActor.h"
56
57#define VTK_MAX_LABELS    200
58#define VTK_MAX_TICKS     1000
59
60#define VTK_AXIS_TYPE_X   0
61#define VTK_AXIS_TYPE_Y   1
62#define VTK_AXIS_TYPE_Z   2
63
64#define VTK_TICKS_INSIDE  0
65#define VTK_TICKS_OUTSIDE 1
66#define VTK_TICKS_BOTH    2
67
68#define VTK_AXIS_POS_MINMIN 0
69#define VTK_AXIS_POS_MINMAX 1
70#define VTK_AXIS_POS_MAXMAX 2
71#define VTK_AXIS_POS_MAXMIN 3
72
73class vtkRpAxisFollower;
74class vtkCamera;
75class vtkCoordinate;
76class vtkFollower;
77class vtkPoints;
78class vtkPolyData;
79class vtkPolyDataMapper;
80class vtkProperty2D;
81class vtkStringArray;
82class vtkTextActor;
83class vtkTextProperty;
84class vtkVectorText;
85
86class VTKRENDERINGANNOTATION_EXPORT vtkRpAxisActor : public vtkActor
87{
88 public:
89  vtkTypeMacro(vtkRpAxisActor,vtkActor);
90  void PrintSelf(ostream& os, vtkIndent indent);
91
92  // Description:
93  // Instantiate object.
94  static vtkRpAxisActor *New();
95
96  // Description:
97  // Specify the position of the first point defining the axis.
98  virtual vtkCoordinate *GetPoint1Coordinate();
99  virtual void SetPoint1(double x[3])
100  { this->SetPoint1(x[0], x[1], x[2]); }
101  virtual void SetPoint1(double x, double y, double z);
102  virtual double *GetPoint1();
103
104  // Description:
105  // Specify the position of the second point defining the axis.
106  virtual vtkCoordinate *GetPoint2Coordinate();
107  virtual void SetPoint2(double x[3])
108  { this->SetPoint2(x[0], x[1], x[2]); }
109  virtual void SetPoint2(double x, double y, double z);
110  virtual double *GetPoint2();
111
112  // Description:
113  // Specify the (min,max) axis range. This will be used in the generation
114  // of labels, if labels are visible.
115  vtkSetVector2Macro(Range,double);
116  vtkGetVectorMacro(Range,double,2);
117
118  // Description:
119  // Set or get the bounds for this Actor as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
120  void   SetBounds(double bounds[6]);
121  void   SetBounds(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax);
122  double *GetBounds(void);
123  void   GetBounds(double bounds[6]);
124
125  vtkSetMacro(ScreenSize, double);
126  vtkGetMacro(ScreenSize, double);
127
128  // Description:
129  // Set/Get the format with which to print the labels on the axis.
130  vtkSetStringMacro(LabelFormat);
131  vtkGetStringMacro(LabelFormat);
132
133  // Description:
134  // Set/Get the flag that controls whether the minor ticks are visible.
135  vtkSetMacro(MinorTicksVisible, int);
136  vtkGetMacro(MinorTicksVisible, int);
137  vtkBooleanMacro(MinorTicksVisible, int);
138
139
140  // Description:
141  // Set/Get the title of the axis actor,
142  void SetTitle(const char *t);
143  vtkGetStringMacro(Title);
144
145  // Description:
146  // Set/Get the size of the major tick marks
147  vtkSetMacro(MajorTickSize, double);
148  vtkGetMacro(MajorTickSize, double);
149
150  // Description:
151  // Set/Get the size of the major tick marks
152  vtkSetMacro(MinorTickSize, double);
153  vtkGetMacro(MinorTickSize, double);
154
155  // Description:
156  // Set/Get the location of the ticks.
157  vtkSetClampMacro(TickLocation, int, VTK_TICKS_INSIDE, VTK_TICKS_BOTH);
158  vtkGetMacro(TickLocation, int);
159
160  void SetTickLocationToInside(void)
161  { this->SetTickLocation(VTK_TICKS_INSIDE); };
162  void SetTickLocationToOutside(void)
163  { this->SetTickLocation(VTK_TICKS_OUTSIDE); };
164  void SetTickLocationToBoth(void)
165  { this->SetTickLocation(VTK_TICKS_BOTH); };
166
167  // Description:
168  // Set/Get visibility of the axis line.
169  vtkSetMacro(AxisVisibility, int);
170  vtkGetMacro(AxisVisibility, int);
171  vtkBooleanMacro(AxisVisibility, int);
172
173  // Description:
174  // Set/Get visibility of the axis tick marks.
175  vtkSetMacro(TickVisibility, int);
176  vtkGetMacro(TickVisibility, int);
177  vtkBooleanMacro(TickVisibility, int);
178
179  // Description:
180  // Set/Get visibility of the axis labels.
181  vtkSetMacro(LabelVisibility, int);
182  vtkGetMacro(LabelVisibility, int);
183  vtkBooleanMacro(LabelVisibility, int);
184
185  // Description:
186  // Set/Get visibility of the axis title.
187  vtkSetMacro(TitleVisibility, int);
188  vtkGetMacro(TitleVisibility, int);
189  vtkBooleanMacro(TitleVisibility, int);
190
191  // Description:
192  // Set/Get the axis title text property.
193  virtual void SetTitleTextProperty(vtkTextProperty *p);
194  vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
195
196  // Description:
197  // Set/Get the axis labels text property.
198  virtual void SetLabelTextProperty(vtkTextProperty *p);
199  vtkGetObjectMacro(LabelTextProperty,vtkTextProperty);
200
201  // Description:
202  // Get/Set axis actor property (axis and its ticks)
203  void SetAxisLinesProperty(vtkProperty *);
204  vtkProperty* GetAxisLinesProperty();
205
206  // Description:
207  // Get/Set gridlines actor property (outer grid lines)
208  void SetGridlinesProperty(vtkProperty *);
209  vtkProperty* GetGridlinesProperty();
210
211  // Description:
212  // Get/Set inner gridlines actor property
213  void SetInnerGridlinesProperty(vtkProperty *);
214  vtkProperty* GetInnerGridlinesProperty();
215
216  // Description:
217  // Get/Set gridPolys actor property (grid quads)
218  void SetGridpolysProperty(vtkProperty *);
219  vtkProperty* GetGridpolysProperty();
220
221  // Description:
222  // Set/Get whether gridlines should be drawn.
223  vtkSetMacro(DrawGridlines, int);
224  vtkGetMacro(DrawGridlines, int);
225  vtkBooleanMacro(DrawGridlines, int);
226
227  // Description:
228  // Set/Get whether ONLY the gridlines should be drawn.
229  // This will only draw GridLines and will skip any other part of the rendering
230  // such as Axis/Tick/Title/...
231  vtkSetMacro(DrawGridlinesOnly, int);
232  vtkGetMacro(DrawGridlinesOnly, int);
233  vtkBooleanMacro(DrawGridlinesOnly, int);
234
235  vtkSetMacro(DrawGridlinesLocation, int);
236  vtkGetMacro(DrawGridlinesLocation, int);
237
238  // Description:
239  // Set/Get whether inner gridlines should be drawn.
240  vtkSetMacro(DrawInnerGridlines, int);
241  vtkGetMacro(DrawInnerGridlines, int);
242  vtkBooleanMacro(DrawInnerGridlines, int);
243
244  // Description:
245  // Set/Get the length to use when drawing gridlines.
246  vtkSetMacro(GridlineXLength, double);
247  vtkGetMacro(GridlineXLength, double);
248  vtkSetMacro(GridlineYLength, double);
249  vtkGetMacro(GridlineYLength, double);
250  vtkSetMacro(GridlineZLength, double);
251  vtkGetMacro(GridlineZLength, double);
252
253  // Description:
254  // Set/Get whether gridpolys should be drawn.
255  vtkSetMacro(DrawGridpolys, int);
256  vtkGetMacro(DrawGridpolys, int);
257  vtkBooleanMacro(DrawGridpolys, int);
258
259  // Description:
260  // Set/Get the type of this axis.
261  vtkSetClampMacro(AxisType, int, VTK_AXIS_TYPE_X, VTK_AXIS_TYPE_Z);
262  vtkGetMacro(AxisType, int);
263  void SetAxisTypeToX(void) { this->SetAxisType(VTK_AXIS_TYPE_X); };
264  void SetAxisTypeToY(void) { this->SetAxisType(VTK_AXIS_TYPE_Y); };
265  void SetAxisTypeToZ(void) { this->SetAxisType(VTK_AXIS_TYPE_Z); };
266
267  // Description:
268  // Set/Get the position of this axis (in relation to an an
269  // assumed bounding box).  For an x-type axis, MINMIN corresponds
270  // to the x-edge in the bounding box where Y values are minimum and
271  // Z values are minimum. For a y-type axis, MAXMIN corresponds to the
272  // y-edge where X values are maximum and Z values are minimum.
273  //
274  vtkSetClampMacro(AxisPosition, int, VTK_AXIS_POS_MINMIN, VTK_AXIS_POS_MAXMIN);
275  vtkGetMacro(AxisPosition, int);
276
277  void SetAxisPositionToMinMin(void)
278  { this->SetAxisPosition(VTK_AXIS_POS_MINMIN); };
279  void SetAxisPositionToMinMax(void)
280  { this->SetAxisPosition(VTK_AXIS_POS_MINMAX); };
281  void SetAxisPositionToMaxMax(void)
282  { this->SetAxisPosition(VTK_AXIS_POS_MAXMAX); };
283  void SetAxisPositionToMaxMin(void)
284  { this->SetAxisPosition(VTK_AXIS_POS_MAXMIN); };
285
286  // Description:
287  // Set/Get the camera for this axis.  The camera is used by the
288  // labels to 'follow' the camera and be legible from any viewpoint.
289  virtual void SetCamera(vtkCamera*);
290  vtkGetObjectMacro(Camera, vtkCamera);
291
292  // Description:
293  // Draw the axis.
294  virtual int RenderOpaqueGeometry(vtkViewport* viewport);
295  virtual int RenderTranslucentGeometry(vtkViewport* viewport);
296  virtual int RenderTranslucentPolygonalGeometry(vtkViewport* viewport);
297  virtual int RenderOverlay(vtkViewport* viewport);
298  int HasTranslucentPolygonalGeometry();
299
300  // Description:
301  // Release any graphics resources that are being consumed by this actor.
302  // The parameter window could be used to determine which graphic
303  // resources to release.
304  void ReleaseGraphicsResources(vtkWindow *);
305
306//BTX
307  double ComputeMaxLabelLength(const double [3]);
308  double ComputeTitleLength(const double [3]);
309//ETX
310  void SetLabelScale(const double);
311  void SetTitleScale(const double);
312
313  // Description:
314  // Set/Get the starting position for minor and major tick points,
315  // and the delta values that determine their spacing.
316  vtkSetMacro(MinorStart, double);
317  vtkGetMacro(MinorStart, double);
318  double GetMajorStart(int axis);
319  void SetMajorStart(int axis,double value);
320  //vtkSetMacro(MajorStart, double);
321  //vtkGetMacro(MajorStart, double);
322  vtkSetMacro(DeltaMinor, double);
323  vtkGetMacro(DeltaMinor, double);
324  double GetDeltaMajor(int axis);
325  void SetDeltaMajor(int axis,double value);
326  //vtkSetMacro(DeltaMajor, double);
327  //vtkGetMacro(DeltaMajor, double);
328
329  // Description:
330  // Set/Get the starting position for minor and major tick points on
331  // the range and the delta values that determine their spacing. The
332  // range and the position need not be identical. ie the displayed
333  // values need not match the actual positions in 3D space.
334  vtkSetMacro(MinorRangeStart, double);
335  vtkGetMacro(MinorRangeStart, double);
336  vtkSetMacro(MajorRangeStart, double);
337  vtkGetMacro(MajorRangeStart, double);
338  vtkSetMacro(DeltaRangeMinor, double);
339  vtkGetMacro(DeltaRangeMinor, double);
340  vtkSetMacro(DeltaRangeMajor, double);
341  vtkGetMacro(DeltaRangeMajor, double);
342
343//BTX
344  void SetLabels(vtkStringArray *labels);
345//ETX
346
347  void BuildAxis(vtkViewport *viewport, bool);
348
349//BTX
350  // Description:
351  // Get title actor and it is responsible for drawing
352  // title text.
353  vtkGetObjectMacro(TitleActor,  vtkRpAxisFollower);
354
355  // Description:
356  // Get label actors responsigle for drawing label text.
357  inline vtkRpAxisFollower** GetLabelActors()
358    {
359    return this->LabelActors;
360    }
361//ETX
362
363  // Description:
364  // Get total number of labels built. Once built
365  // this count does not change.
366  vtkGetMacro(NumberOfLabelsBuilt, int);
367
368  // Description:
369  // Set/Get flag whether to calculate title offset.
370  // Default is true.
371  vtkSetMacro(CalculateTitleOffset, int);
372  vtkGetMacro(CalculateTitleOffset, int);
373  vtkBooleanMacro(CalculateTitleOffset, int);
374
375  // Description:
376  // Set/Get flag whether to calculate label offset.
377  // Default is true.
378  vtkSetMacro(CalculateLabelOffset, int);
379  vtkGetMacro(CalculateLabelOffset, int);
380  vtkBooleanMacro(CalculateLabelOffset, int);
381
382  // Description:
383  // Set/Get the 2D mode
384  vtkSetMacro(Use2DMode, int);
385  vtkGetMacro(Use2DMode, int);
386
387  // Description:
388  // Set/Get the 2D mode the vertical offset for X title in 2D mode
389  vtkSetMacro(VerticalOffsetXTitle2D, double);
390  vtkGetMacro(VerticalOffsetXTitle2D, double);
391
392  // Description:
393  // Set/Get the 2D mode the horizontal offset for Y title in 2D mode
394  vtkSetMacro(HorizontalOffsetYTitle2D, double);
395  vtkGetMacro(HorizontalOffsetYTitle2D, double);
396
397  // Description:
398  // Set/Get whether title position must be saved in 2D mode
399  vtkSetMacro(SaveTitlePosition, int);
400  vtkGetMacro(SaveTitlePosition, int);
401
402  // Description:
403  // Provide real vector for non aligned axis
404  vtkSetVector3Macro(AxisBaseForX, double);
405  vtkGetVector3Macro(AxisBaseForX, double);
406
407  // Description:
408  // Provide real vector for non aligned axis
409  vtkSetVector3Macro(AxisBaseForY, double);
410  vtkGetVector3Macro(AxisBaseForY, double);
411
412  // Description:
413  // Provide real vector for non aligned axis
414  vtkSetVector3Macro(AxisBaseForZ, double);
415  vtkGetVector3Macro(AxisBaseForZ, double);
416
417  // Description:
418  // Notify the axes that is not part of a cube anymore
419  vtkSetMacro(AxisOnOrigin,int);
420  vtkGetMacro(AxisOnOrigin,int);
421
422
423 protected:
424  vtkRpAxisActor();
425  ~vtkRpAxisActor();
426
427  char  *Title;
428  double  Range[2];
429  double  LastRange[2];
430  char  *LabelFormat;
431  int    NumberOfLabelsBuilt;
432  int    MinorTicksVisible;
433  int    LastMinorTicksVisible;
434  int    TickLocation;
435
436  int    DrawGridlines;
437  int    DrawGridlinesOnly;
438  int    LastDrawGridlines;
439  int    DrawGridlinesLocation; // 0: all | 1: closest | 2: farest
440  int    LastDrawGridlinesLocation; // 0: all | 1: closest | 2: farest
441  double GridlineXLength;
442  double GridlineYLength;
443  double GridlineZLength;
444
445  int    DrawInnerGridlines;
446  int    LastDrawInnerGridlines;
447
448  int    DrawGridpolys;
449  int    LastDrawGridpolys;
450
451  int    AxisVisibility;
452  int    TickVisibility;
453  int    LastTickVisibility;
454  int    LabelVisibility;
455  int    TitleVisibility;
456
457  int    AxisType;
458  int    AxisPosition;
459  double  Bounds[6];
460
461  double AxisBaseForX[3];
462  double AxisBaseForY[3];
463  double AxisBaseForZ[3];
464
465 private:
466  vtkRpAxisActor(const vtkRpAxisActor&); // Not implemented
467  void operator=(const vtkRpAxisActor&); // Not implemented
468
469  void TransformBounds(vtkViewport *, double bnds[6]);
470
471  void AutoScale(vtkViewport *viewport);
472  double AutoScale(vtkViewport *viewport, double screenSize,
473                   double position[3]);
474
475  void BuildLabels(vtkViewport *, bool);
476  void BuildLabels2D(vtkViewport *, bool);
477  void SetLabelPositions(vtkViewport *, bool);
478  void SetLabelPositions2D(vtkViewport *, bool);
479
480  void BuildTitle(bool);
481  void BuildTitle2D(vtkViewport *viewport, bool);
482
483  void SetAxisPointsAndLines(void);
484  bool BuildTickPoints(double p1[3], double p2[3], bool force);
485
486  bool TickVisibilityChanged(void);
487  vtkProperty *NewTitleProperty();
488  vtkProperty2D *NewTitleProperty2D();
489  vtkProperty *NewLabelProperty();
490
491  bool BoundsDisplayCoordinateChanged(vtkViewport *viewport);
492
493  vtkCoordinate *Point1Coordinate;
494  vtkCoordinate *Point2Coordinate;
495
496  double  MajorTickSize;
497  double  MinorTickSize;
498
499  // For each axis (for the inner gridline generation)
500  double  MajorStart[3];
501  double  DeltaMajor[3];
502  double  MinorStart;
503  double  DeltaMinor;
504
505  // For the ticks, w.r.t to the set range
506  double  MajorRangeStart;
507  double  MinorRangeStart;
508  double  DeltaRangeMinor;
509  double  DeltaRangeMajor;
510
511  int    LastAxisPosition;
512  int    LastAxisType;
513  int    LastTickLocation;
514  double LastLabelStart;
515
516  vtkPoints         *MinorTickPts;
517  vtkPoints         *MajorTickPts;
518  vtkPoints         *GridlinePts;
519  vtkPoints         *InnerGridlinePts;
520  vtkPoints         *GridpolyPts;
521
522  vtkVectorText     *TitleVector;
523  vtkPolyDataMapper *TitleMapper;
524  vtkRpAxisFollower *TitleActor;
525  vtkTextActor      *TitleActor2D;
526  vtkTextProperty   *TitleTextProperty;
527
528  vtkVectorText     **LabelVectors;
529  vtkPolyDataMapper **LabelMappers;
530  vtkRpAxisFollower **LabelActors;
531  vtkTextActor      **LabelActors2D;
532  vtkTextProperty    *LabelTextProperty;
533
534  vtkPolyData        *AxisLines;
535  vtkPolyDataMapper  *AxisLinesMapper;
536  vtkActor           *AxisLinesActor;
537  vtkPolyData        *Gridlines;
538  vtkPolyDataMapper  *GridlinesMapper;
539  vtkActor           *GridlinesActor;
540  vtkPolyData        *InnerGridlines;
541  vtkPolyDataMapper  *InnerGridlinesMapper;
542  vtkActor           *InnerGridlinesActor;
543  vtkPolyData        *Gridpolys;
544  vtkPolyDataMapper  *GridpolysMapper;
545  vtkActor           *GridpolysActor;
546
547  vtkCamera          *Camera;
548  vtkTimeStamp        BuildTime;
549  vtkTimeStamp        BuildTickPointsTime;
550  vtkTimeStamp        BoundsTime;
551  vtkTimeStamp        LabelBuildTime;
552  vtkTimeStamp        TitleTextTime;
553
554  int                 AxisOnOrigin;
555
556  int                 AxisHasZeroLength;
557
558  int                 CalculateTitleOffset;
559  int                 CalculateLabelOffset;
560
561  double              ScreenSize;
562
563  // Description:
564  // Use xy-axis only when Use2DMode=1:
565  int                 Use2DMode;
566
567  // Description:
568  // Vertical offset in display coordinates for X axis title (used in 2D mode only)
569  // Default: -40
570  double              VerticalOffsetXTitle2D;
571
572  // Description:
573  // Vertical offset in display coordinates for X axis title (used in 2D mode only)
574  // Default: -50
575  double              HorizontalOffsetYTitle2D;
576
577  // Description:
578  // Save title position (used in 2D mode only):
579  // val = 0 : no need to save position (doesn't stick actors in a position)
580  // val = 1 : positions have to be saved during the next render pass
581  // val = 2 : positions are saved; use them
582  int                 SaveTitlePosition;
583
584  // Description:
585  // Constant position for the title (used in 2D mode only)
586  double              TitleConstantPosition[2];
587
588  // Description:
589  // True if the 2D title has to be built, false otherwise
590  bool                NeedBuild2D;
591
592  double              LastMinDisplayCoordinate[3];
593  double              LastMaxDisplayCoordinate[3];
594};
595
596
597#endif
Note: See TracBrowser for help on using the repository browser.