source: vtkvis/trunk/vtkRpAxisActor.h @ 6307

Last change on this file since 6307 was 5802, checked in by ldelgass, 9 years ago

Update custom cube axes: rebase on version in VTK 6.1.0 plus backported fixes
from 6.3.0rc1, but without TextActor3D option.

  • Property svn:eol-style set to native
File size: 19.0 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(const 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  // Description:
126  // Set/Get the format with which to print the labels on the axis.
127  vtkSetStringMacro(LabelFormat);
128  vtkGetStringMacro(LabelFormat);
129
130  // Description:
131  // Set/Get the flag that controls whether the minor ticks are visible.
132  vtkSetMacro(MinorTicksVisible, int);
133  vtkGetMacro(MinorTicksVisible, int);
134  vtkBooleanMacro(MinorTicksVisible, int);
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 the axis title text property.
189  virtual void SetTitleTextProperty(vtkTextProperty *p);
190  vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
191
192  // Description:
193  // Set/Get the axis labels text property.
194  virtual void SetLabelTextProperty(vtkTextProperty *p);
195  vtkGetObjectMacro(LabelTextProperty,vtkTextProperty);
196
197  // Description:
198  // Get/Set axis actor property (axis and its ticks)
199  void SetAxisLinesProperty(vtkProperty *);
200  vtkProperty* GetAxisLinesProperty();
201
202  // Description:
203  // Get/Set gridlines actor property (outer grid lines)
204  void SetGridlinesProperty(vtkProperty *);
205  vtkProperty* GetGridlinesProperty();
206
207  // Description:
208  // Get/Set inner gridlines actor property
209  void SetInnerGridlinesProperty(vtkProperty *);
210  vtkProperty* GetInnerGridlinesProperty();
211
212  // Description:
213  // Get/Set gridPolys actor property (grid quads)
214  void SetGridpolysProperty(vtkProperty *);
215  vtkProperty* GetGridpolysProperty();
216
217  // Description:
218  // Set/Get whether gridlines should be drawn.
219  vtkSetMacro(DrawGridlines, int);
220  vtkGetMacro(DrawGridlines, int);
221  vtkBooleanMacro(DrawGridlines, int);
222
223  // Description:
224  // Set/Get whether ONLY the gridlines should be drawn.
225  // This will only draw GridLines and will skip any other part of the rendering
226  // such as Axis/Tick/Title/...
227  vtkSetMacro(DrawGridlinesOnly, int);
228  vtkGetMacro(DrawGridlinesOnly, int);
229  vtkBooleanMacro(DrawGridlinesOnly, int);
230
231  vtkSetMacro(DrawGridlinesLocation, int);
232  vtkGetMacro(DrawGridlinesLocation, int);
233
234  // Description:
235  // Set/Get whether inner gridlines should be drawn.
236  vtkSetMacro(DrawInnerGridlines, int);
237  vtkGetMacro(DrawInnerGridlines, int);
238  vtkBooleanMacro(DrawInnerGridlines, int);
239
240  // Description:
241  // Set/Get the length to use when drawing gridlines.
242  vtkSetMacro(GridlineXLength, double);
243  vtkGetMacro(GridlineXLength, double);
244  vtkSetMacro(GridlineYLength, double);
245  vtkGetMacro(GridlineYLength, double);
246  vtkSetMacro(GridlineZLength, double);
247  vtkGetMacro(GridlineZLength, double);
248
249  // Description:
250  // Set/Get whether gridpolys should be drawn.
251  vtkSetMacro(DrawGridpolys, int);
252  vtkGetMacro(DrawGridpolys, int);
253  vtkBooleanMacro(DrawGridpolys, int);
254
255  // Description:
256  // Set/Get the type of this axis.
257  vtkSetClampMacro(AxisType, int, VTK_AXIS_TYPE_X, VTK_AXIS_TYPE_Z);
258  vtkGetMacro(AxisType, int);
259  void SetAxisTypeToX(void) { this->SetAxisType(VTK_AXIS_TYPE_X); };
260  void SetAxisTypeToY(void) { this->SetAxisType(VTK_AXIS_TYPE_Y); };
261  void SetAxisTypeToZ(void) { this->SetAxisType(VTK_AXIS_TYPE_Z); };
262
263  // Description:
264  // Set/Get the position of this axis (in relation to an an
265  // assumed bounding box).  For an x-type axis, MINMIN corresponds
266  // to the x-edge in the bounding box where Y values are minimum and
267  // Z values are minimum. For a y-type axis, MAXMIN corresponds to the
268  // y-edge where X values are maximum and Z values are minimum.
269  //
270  vtkSetClampMacro(AxisPosition, int, VTK_AXIS_POS_MINMIN, VTK_AXIS_POS_MAXMIN);
271  vtkGetMacro(AxisPosition, int);
272
273  void SetAxisPositionToMinMin(void)
274  { this->SetAxisPosition(VTK_AXIS_POS_MINMIN); };
275  void SetAxisPositionToMinMax(void)
276  { this->SetAxisPosition(VTK_AXIS_POS_MINMAX); };
277  void SetAxisPositionToMaxMax(void)
278  { this->SetAxisPosition(VTK_AXIS_POS_MAXMAX); };
279  void SetAxisPositionToMaxMin(void)
280  { this->SetAxisPosition(VTK_AXIS_POS_MAXMIN); };
281
282  // Description:
283  // Set/Get the camera for this axis.  The camera is used by the
284  // labels to 'follow' the camera and be legible from any viewpoint.
285  virtual void SetCamera(vtkCamera*);
286  vtkGetObjectMacro(Camera, vtkCamera);
287
288  // Description:
289  // Draw the axis.
290  virtual int RenderOpaqueGeometry(vtkViewport* viewport);
291  virtual int RenderTranslucentGeometry(vtkViewport* viewport);
292  virtual int RenderTranslucentPolygonalGeometry(vtkViewport* viewport);
293  virtual int RenderOverlay(vtkViewport* viewport);
294  int HasTranslucentPolygonalGeometry();
295
296  // Description:
297  // Release any graphics resources that are being consumed by this actor.
298  // The parameter window could be used to determine which graphic
299  // resources to release.
300  void ReleaseGraphicsResources(vtkWindow *);
301
302//BTX
303  double ComputeMaxLabelLength(const double [3]);
304  double ComputeTitleLength(const double [3]);
305//ETX
306  void SetLabelScale(const double scale);
307  void SetLabelScale(int labelIndex, const double scale);
308  void SetTitleScale(const double scale);
309
310  // Description:
311  // Set/Get the starting position for minor and major tick points,
312  // and the delta values that determine their spacing.
313  vtkSetMacro(MinorStart, double);
314  vtkGetMacro(MinorStart, double);
315  double GetMajorStart(int axis);
316  void SetMajorStart(int axis,double value);
317  //vtkSetMacro(MajorStart, double);
318  //vtkGetMacro(MajorStart, double);
319  vtkSetMacro(DeltaMinor, double);
320  vtkGetMacro(DeltaMinor, double);
321  double GetDeltaMajor(int axis);
322  void SetDeltaMajor(int axis,double value);
323  //vtkSetMacro(DeltaMajor, double);
324  //vtkGetMacro(DeltaMajor, double);
325
326  // Description:
327  // Set/Get the starting position for minor and major tick points on
328  // the range and the delta values that determine their spacing. The
329  // range and the position need not be identical. ie the displayed
330  // values need not match the actual positions in 3D space.
331  vtkSetMacro(MinorRangeStart, double);
332  vtkGetMacro(MinorRangeStart, double);
333  vtkSetMacro(MajorRangeStart, double);
334  vtkGetMacro(MajorRangeStart, double);
335  vtkSetMacro(DeltaRangeMinor, double);
336  vtkGetMacro(DeltaRangeMinor, double);
337  vtkSetMacro(DeltaRangeMajor, double);
338  vtkGetMacro(DeltaRangeMajor, double);
339
340//BTX
341  void SetLabels(vtkStringArray *labels);
342//ETX
343
344  void BuildAxis(vtkViewport *viewport, bool);
345
346//BTX
347  // Description:
348  // Get title actor and it is responsible for drawing
349  // title text.
350  vtkGetObjectMacro(TitleActor,  vtkRpAxisFollower);
351
352  // Description:
353  // Get label actors responsigle for drawing label text.
354  inline vtkRpAxisFollower** GetLabelActors()
355    {
356    return this->LabelActors;
357    }
358//ETX
359
360  // Description:
361  // Get total number of labels built. Once built
362  // this count does not change.
363  vtkGetMacro(NumberOfLabelsBuilt, int);
364
365  // Description:
366  // Set/Get flag whether to calculate title offset.
367  // Default is true.
368  vtkSetMacro(CalculateTitleOffset, int);
369  vtkGetMacro(CalculateTitleOffset, int);
370  vtkBooleanMacro(CalculateTitleOffset, int);
371
372  // Description:
373  // Set/Get flag whether to calculate label offset.
374  // Default is true.
375  vtkSetMacro(CalculateLabelOffset, int);
376  vtkGetMacro(CalculateLabelOffset, int);
377  vtkBooleanMacro(CalculateLabelOffset, int);
378
379  // Description:
380  // Set/Get the 2D mode
381  vtkSetMacro(Use2DMode, int);
382  vtkGetMacro(Use2DMode, int);
383
384  // Description:
385  // Set/Get the 2D mode the vertical offset for X title in 2D mode
386  vtkSetMacro(VerticalOffsetXTitle2D, double);
387  vtkGetMacro(VerticalOffsetXTitle2D, double);
388
389  // Description:
390  // Set/Get the 2D mode the horizontal offset for Y title in 2D mode
391  vtkSetMacro(HorizontalOffsetYTitle2D, double);
392  vtkGetMacro(HorizontalOffsetYTitle2D, double);
393
394  // Description:
395  // Set/Get whether title position must be saved in 2D mode
396  vtkSetMacro(SaveTitlePosition, int);
397  vtkGetMacro(SaveTitlePosition, int);
398
399  // Description:
400  // Provide real vector for non aligned axis
401  vtkSetVector3Macro(AxisBaseForX, double);
402  vtkGetVector3Macro(AxisBaseForX, double);
403
404  // Description:
405  // Provide real vector for non aligned axis
406  vtkSetVector3Macro(AxisBaseForY, double);
407  vtkGetVector3Macro(AxisBaseForY, double);
408
409  // Description:
410  // Provide real vector for non aligned axis
411  vtkSetVector3Macro(AxisBaseForZ, double);
412  vtkGetVector3Macro(AxisBaseForZ, double);
413
414  // Description:
415  // Notify the axes that is not part of a cube anymore
416  vtkSetMacro(AxisOnOrigin,int);
417  vtkGetMacro(AxisOnOrigin,int);
418
419  // Description:
420  // Set/Get the offsets used to position texts.
421  vtkSetMacro(LabelOffset, double);
422  vtkGetMacro(LabelOffset, double);
423  vtkSetMacro(TitleOffset, double);
424  vtkGetMacro(TitleOffset, double);
425  vtkSetMacro(ScreenSize, double);
426  vtkGetMacro(ScreenSize, double);
427
428 protected:
429  vtkRpAxisActor();
430  ~vtkRpAxisActor();
431
432  char  *Title;
433  double  Range[2];
434  double  LastRange[2];
435  char  *LabelFormat;
436  int    NumberOfLabelsBuilt;
437  int    MinorTicksVisible;
438  int    LastMinorTicksVisible;
439  int    TickLocation;
440
441  int    DrawGridlines;
442  int    DrawGridlinesOnly;
443  int    LastDrawGridlines;
444  int    DrawGridlinesLocation; // 0: all | 1: closest | 2: farest
445  int    LastDrawGridlinesLocation; // 0: all | 1: closest | 2: farest
446  double GridlineXLength;
447  double GridlineYLength;
448  double GridlineZLength;
449
450  int    DrawInnerGridlines;
451  int    LastDrawInnerGridlines;
452
453  int    DrawGridpolys;
454  int    LastDrawGridpolys;
455
456  int    AxisVisibility;
457  int    TickVisibility;
458  int    LastTickVisibility;
459  int    LabelVisibility;
460  int    TitleVisibility;
461
462  int    AxisType;
463  int    AxisPosition;
464  double  Bounds[6];
465
466  double AxisBaseForX[3];
467  double AxisBaseForY[3];
468  double AxisBaseForZ[3];
469
470 private:
471  vtkRpAxisActor(const vtkRpAxisActor&); // Not implemented
472  void operator=(const vtkRpAxisActor&); // Not implemented
473
474  void TransformBounds(vtkViewport *, double bnds[6]);
475
476  void BuildLabels(vtkViewport *, bool);
477  void BuildLabels2D(vtkViewport *, bool);
478  void SetLabelPositions(vtkViewport *, bool);
479  void SetLabelPositions2D(vtkViewport *, bool);
480
481  void BuildTitle(bool);
482  void BuildTitle2D(vtkViewport *viewport, bool);
483
484  void SetAxisPointsAndLines(void);
485  bool BuildTickPoints(double p1[3], double p2[3], bool force);
486
487  bool TickVisibilityChanged(void);
488  vtkProperty *NewTitleProperty();
489  vtkProperty2D *NewTitleProperty2D();
490  vtkProperty *NewLabelProperty();
491
492  bool BoundsDisplayCoordinateChanged(vtkViewport *viewport);
493
494  vtkCoordinate *Point1Coordinate;
495  vtkCoordinate *Point2Coordinate;
496
497  double  MajorTickSize;
498  double  MinorTickSize;
499
500  // For each axis (for the inner gridline generation)
501  double  MajorStart[3];
502  double  DeltaMajor[3];
503  double  MinorStart;
504  double  DeltaMinor;
505
506  // For the ticks, w.r.t to the set range
507  double  MajorRangeStart;
508  double  MinorRangeStart;
509  double  DeltaRangeMinor;
510  double  DeltaRangeMajor;
511
512  int    LastAxisPosition;
513  int    LastAxisType;
514  int    LastTickLocation;
515  double LastLabelStart;
516
517  vtkPoints         *MinorTickPts;
518  vtkPoints         *MajorTickPts;
519  vtkPoints         *GridlinePts;
520  vtkPoints         *InnerGridlinePts;
521  vtkPoints         *GridpolyPts;
522
523  vtkVectorText     *TitleVector;
524  vtkPolyDataMapper *TitleMapper;
525  vtkRpAxisFollower *TitleActor;
526  vtkTextActor      *TitleActor2D;
527  vtkTextProperty   *TitleTextProperty;
528
529  vtkVectorText     **LabelVectors;
530  vtkPolyDataMapper **LabelMappers;
531  vtkRpAxisFollower **LabelActors;
532  vtkTextActor      **LabelActors2D;
533  vtkTextProperty    *LabelTextProperty;
534
535  vtkPolyData        *AxisLines;
536  vtkPolyDataMapper  *AxisLinesMapper;
537  vtkActor           *AxisLinesActor;
538  vtkPolyData        *Gridlines;
539  vtkPolyDataMapper  *GridlinesMapper;
540  vtkActor           *GridlinesActor;
541  vtkPolyData        *InnerGridlines;
542  vtkPolyDataMapper  *InnerGridlinesMapper;
543  vtkActor           *InnerGridlinesActor;
544  vtkPolyData        *Gridpolys;
545  vtkPolyDataMapper  *GridpolysMapper;
546  vtkActor           *GridpolysActor;
547
548  vtkCamera          *Camera;
549  vtkTimeStamp        BuildTime;
550  vtkTimeStamp        BuildTickPointsTime;
551  vtkTimeStamp        BoundsTime;
552  vtkTimeStamp        LabelBuildTime;
553  vtkTimeStamp        TitleTextTime;
554
555  int                 AxisOnOrigin;
556
557  int                 AxisHasZeroLength;
558
559  int                 CalculateTitleOffset;
560  int                 CalculateLabelOffset;
561
562  // Description:
563  // Use xy-axis only when Use2DMode=1:
564  int                 Use2DMode;
565
566  // Description:
567  // Vertical offset in display coordinates for X axis title (used in 2D mode only)
568  // Default: -40
569  double              VerticalOffsetXTitle2D;
570
571  // Description:
572  // Vertical offset in display coordinates for X axis title (used in 2D mode only)
573  // Default: -50
574  double              HorizontalOffsetYTitle2D;
575
576  // Description:
577  // Save title position (used in 2D mode only):
578  // val = 0 : no need to save position (doesn't stick actors in a position)
579  // val = 1 : positions have to be saved during the next render pass
580  // val = 2 : positions are saved; use them
581  int                 SaveTitlePosition;
582
583  // Description:
584  // Constant position for the title (used in 2D mode only)
585  double              TitleConstantPosition[2];
586
587  // Description:
588  // True if the 2D title has to be built, false otherwise
589  bool                NeedBuild2D;
590
591  double              LastMinDisplayCoordinate[3];
592  double              LastMaxDisplayCoordinate[3];
593
594  // Description:
595  // Offsets used to position text.
596  double ScreenSize;
597  double LabelOffset;
598  double TitleOffset;
599};
600
601#endif
Note: See TracBrowser for help on using the repository browser.