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

Last change on this file since 3479 was 3479, checked in by ldelgass, 10 years ago

Update custom axes to VTK 6 versions, use local customized classes instead of
patched VTK runtime versions.

  • Property svn:eol-style set to native
File size: 18.6 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  // 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
137  // Description:
138  // Set/Get the title of the axis actor,
139  void SetTitle(const char *t);
140  vtkGetStringMacro(Title);
141
142  // Description:
143  // Set/Get the size of the major tick marks
144  vtkSetMacro(MajorTickSize, double);
145  vtkGetMacro(MajorTickSize, double);
146
147  // Description:
148  // Set/Get the size of the major tick marks
149  vtkSetMacro(MinorTickSize, double);
150  vtkGetMacro(MinorTickSize, double);
151
152  // Description:
153  // Set/Get the location of the ticks.
154  vtkSetClampMacro(TickLocation, int, VTK_TICKS_INSIDE, VTK_TICKS_BOTH);
155  vtkGetMacro(TickLocation, int);
156
157  void SetTickLocationToInside(void)
158  { this->SetTickLocation(VTK_TICKS_INSIDE); };
159  void SetTickLocationToOutside(void)
160  { this->SetTickLocation(VTK_TICKS_OUTSIDE); };
161  void SetTickLocationToBoth(void)
162  { this->SetTickLocation(VTK_TICKS_BOTH); };
163
164  // Description:
165  // Set/Get visibility of the axis line.
166  vtkSetMacro(AxisVisibility, int);
167  vtkGetMacro(AxisVisibility, int);
168  vtkBooleanMacro(AxisVisibility, int);
169
170  // Description:
171  // Set/Get visibility of the axis tick marks.
172  vtkSetMacro(TickVisibility, int);
173  vtkGetMacro(TickVisibility, int);
174  vtkBooleanMacro(TickVisibility, int);
175
176  // Description:
177  // Set/Get visibility of the axis labels.
178  vtkSetMacro(LabelVisibility, int);
179  vtkGetMacro(LabelVisibility, int);
180  vtkBooleanMacro(LabelVisibility, int);
181
182  // Description:
183  // Set/Get visibility of the axis title.
184  vtkSetMacro(TitleVisibility, int);
185  vtkGetMacro(TitleVisibility, int);
186  vtkBooleanMacro(TitleVisibility, int);
187
188  // Description:
189  // Set/Get the axis title text property.
190  virtual void SetTitleTextProperty(vtkTextProperty *p);
191  vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
192
193  // Description:
194  // Set/Get the axis labels text property.
195  virtual void SetLabelTextProperty(vtkTextProperty *p);
196  vtkGetObjectMacro(LabelTextProperty,vtkTextProperty);
197
198  // Description:
199  // Get/Set axis actor property (axis and its ticks)
200  void SetAxisLinesProperty(vtkProperty *);
201  vtkProperty* GetAxisLinesProperty();
202
203  // Description:
204  // Get/Set gridlines actor property (outer grid lines)
205  void SetGridlinesProperty(vtkProperty *);
206  vtkProperty* GetGridlinesProperty();
207
208  // Description:
209  // Get/Set inner gridlines actor property
210  void SetInnerGridlinesProperty(vtkProperty *);
211  vtkProperty* GetInnerGridlinesProperty();
212
213  // Description:
214  // Get/Set gridPolys actor property (grid quads)
215  void SetGridpolysProperty(vtkProperty *);
216  vtkProperty* GetGridpolysProperty();
217
218  // Description:
219  // Set/Get whether gridlines should be drawn.
220  vtkSetMacro(DrawGridlines, int);
221  vtkGetMacro(DrawGridlines, int);
222  vtkBooleanMacro(DrawGridlines, int);
223
224  // Description:
225  // Set/Get whether ONLY the gridlines should be drawn.
226  // This will only draw GridLines and will skip any other part of the rendering
227  // such as Axis/Tick/Title/...
228  vtkSetMacro(DrawGridlinesOnly, int);
229  vtkGetMacro(DrawGridlinesOnly, int);
230  vtkBooleanMacro(DrawGridlinesOnly, int);
231
232  vtkSetMacro(DrawGridlinesLocation, int);
233  vtkGetMacro(DrawGridlinesLocation, int);
234
235  // Description:
236  // Set/Get whether inner gridlines should be drawn.
237  vtkSetMacro(DrawInnerGridlines, int);
238  vtkGetMacro(DrawInnerGridlines, int);
239  vtkBooleanMacro(DrawInnerGridlines, int);
240
241  // Description:
242  // Set/Get the length to use when drawing gridlines.
243  vtkSetMacro(GridlineXLength, double);
244  vtkGetMacro(GridlineXLength, double);
245  vtkSetMacro(GridlineYLength, double);
246  vtkGetMacro(GridlineYLength, double);
247  vtkSetMacro(GridlineZLength, double);
248  vtkGetMacro(GridlineZLength, double);
249
250  // Description:
251  // Set/Get whether gridpolys should be drawn.
252  vtkSetMacro(DrawGridpolys, int);
253  vtkGetMacro(DrawGridpolys, int);
254  vtkBooleanMacro(DrawGridpolys, int);
255
256  // Description:
257  // Set/Get the type of this axis.
258  vtkSetClampMacro(AxisType, int, VTK_AXIS_TYPE_X, VTK_AXIS_TYPE_Z);
259  vtkGetMacro(AxisType, int);
260  void SetAxisTypeToX(void) { this->SetAxisType(VTK_AXIS_TYPE_X); };
261  void SetAxisTypeToY(void) { this->SetAxisType(VTK_AXIS_TYPE_Y); };
262  void SetAxisTypeToZ(void) { this->SetAxisType(VTK_AXIS_TYPE_Z); };
263
264  // Description:
265  // Set/Get the position of this axis (in relation to an an
266  // assumed bounding box).  For an x-type axis, MINMIN corresponds
267  // to the x-edge in the bounding box where Y values are minimum and
268  // Z values are minimum. For a y-type axis, MAXMIN corresponds to the
269  // y-edge where X values are maximum and Z values are minimum.
270  //
271  vtkSetClampMacro(AxisPosition, int, VTK_AXIS_POS_MINMIN, VTK_AXIS_POS_MAXMIN);
272  vtkGetMacro(AxisPosition, int);
273
274  void SetAxisPositionToMinMin(void)
275  { this->SetAxisPosition(VTK_AXIS_POS_MINMIN); };
276  void SetAxisPositionToMinMax(void)
277  { this->SetAxisPosition(VTK_AXIS_POS_MINMAX); };
278  void SetAxisPositionToMaxMax(void)
279  { this->SetAxisPosition(VTK_AXIS_POS_MAXMAX); };
280  void SetAxisPositionToMaxMin(void)
281  { this->SetAxisPosition(VTK_AXIS_POS_MAXMIN); };
282
283  // Description:
284  // Set/Get the camera for this axis.  The camera is used by the
285  // labels to 'follow' the camera and be legible from any viewpoint.
286  virtual void SetCamera(vtkCamera*);
287  vtkGetObjectMacro(Camera, vtkCamera);
288
289  // Description:
290  // Draw the axis.
291  virtual int RenderOpaqueGeometry(vtkViewport* viewport);
292  virtual int RenderTranslucentGeometry(vtkViewport* viewport);
293  virtual int RenderTranslucentPolygonalGeometry(vtkViewport* viewport);
294  virtual int RenderOverlay(vtkViewport* viewport);
295  int HasTranslucentPolygonalGeometry();
296
297  // Description:
298  // Release any graphics resources that are being consumed by this actor.
299  // The parameter window could be used to determine which graphic
300  // resources to release.
301  void ReleaseGraphicsResources(vtkWindow *);
302
303//BTX
304  double ComputeMaxLabelLength(const double [3]);
305  double ComputeTitleLength(const double [3]);
306//ETX
307  void SetLabelScale(const double);
308  void SetTitleScale(const double);
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
420 protected:
421  vtkRpAxisActor();
422  ~vtkRpAxisActor();
423
424  char  *Title;
425  double  Range[2];
426  double  LastRange[2];
427  char  *LabelFormat;
428  int    NumberOfLabelsBuilt;
429  int    MinorTicksVisible;
430  int    LastMinorTicksVisible;
431  int    TickLocation;
432
433  int    DrawGridlines;
434  int    DrawGridlinesOnly;
435  int    LastDrawGridlines;
436  int    DrawGridlinesLocation; // 0: all | 1: closest | 2: farest
437  int    LastDrawGridlinesLocation; // 0: all | 1: closest | 2: farest
438  double GridlineXLength;
439  double GridlineYLength;
440  double GridlineZLength;
441
442  int    DrawInnerGridlines;
443  int    LastDrawInnerGridlines;
444
445  int    DrawGridpolys;
446  int    LastDrawGridpolys;
447
448  int    AxisVisibility;
449  int    TickVisibility;
450  int    LastTickVisibility;
451  int    LabelVisibility;
452  int    TitleVisibility;
453
454  int    AxisType;
455  int    AxisPosition;
456  double  Bounds[6];
457
458  double AxisBaseForX[3];
459  double AxisBaseForY[3];
460  double AxisBaseForZ[3];
461
462 private:
463  vtkRpAxisActor(const vtkRpAxisActor&); // Not implemented
464  void operator=(const vtkRpAxisActor&); // Not implemented
465
466  void TransformBounds(vtkViewport *, double bnds[6]);
467
468  void BuildLabels(vtkViewport *, bool);
469  void BuildLabels2D(vtkViewport *, bool);
470  void SetLabelPositions(vtkViewport *, bool);
471  void SetLabelPositions2D(vtkViewport *, bool);
472
473  void BuildTitle(bool);
474  void BuildTitle2D(vtkViewport *viewport, bool);
475
476  void SetAxisPointsAndLines(void);
477  bool BuildTickPoints(double p1[3], double p2[3], bool force);
478
479  bool TickVisibilityChanged(void);
480  vtkProperty *NewTitleProperty();
481  vtkProperty2D *NewTitleProperty2D();
482  vtkProperty *NewLabelProperty();
483
484  bool BoundsDisplayCoordinateChanged(vtkViewport *viewport);
485
486  vtkCoordinate *Point1Coordinate;
487  vtkCoordinate *Point2Coordinate;
488
489  double  MajorTickSize;
490  double  MinorTickSize;
491
492  // For each axis (for the inner gridline generation)
493  double  MajorStart[3];
494  double  DeltaMajor[3];
495  double  MinorStart;
496  double  DeltaMinor;
497
498  // For the ticks, w.r.t to the set range
499  double  MajorRangeStart;
500  double  MinorRangeStart;
501  double  DeltaRangeMinor;
502  double  DeltaRangeMajor;
503
504  int    LastAxisPosition;
505  int    LastAxisType;
506  int    LastTickLocation;
507  double LastLabelStart;
508
509  vtkPoints         *MinorTickPts;
510  vtkPoints         *MajorTickPts;
511  vtkPoints         *GridlinePts;
512  vtkPoints         *InnerGridlinePts;
513  vtkPoints         *GridpolyPts;
514
515  vtkVectorText     *TitleVector;
516  vtkPolyDataMapper *TitleMapper;
517  vtkRpAxisFollower *TitleActor;
518  vtkTextActor      *TitleActor2D;
519  vtkTextProperty   *TitleTextProperty;
520
521  vtkVectorText     **LabelVectors;
522  vtkPolyDataMapper **LabelMappers;
523  vtkRpAxisFollower **LabelActors;
524  vtkTextActor      **LabelActors2D;
525  vtkTextProperty    *LabelTextProperty;
526
527  vtkPolyData        *AxisLines;
528  vtkPolyDataMapper  *AxisLinesMapper;
529  vtkActor           *AxisLinesActor;
530  vtkPolyData        *Gridlines;
531  vtkPolyDataMapper  *GridlinesMapper;
532  vtkActor           *GridlinesActor;
533  vtkPolyData        *InnerGridlines;
534  vtkPolyDataMapper  *InnerGridlinesMapper;
535  vtkActor           *InnerGridlinesActor;
536  vtkPolyData        *Gridpolys;
537  vtkPolyDataMapper  *GridpolysMapper;
538  vtkActor           *GridpolysActor;
539
540  vtkCamera          *Camera;
541  vtkTimeStamp        BuildTime;
542  vtkTimeStamp        BuildTickPointsTime;
543  vtkTimeStamp        BoundsTime;
544  vtkTimeStamp        LabelBuildTime;
545  vtkTimeStamp        TitleTextTime;
546
547  int                 AxisOnOrigin;
548
549  int                 AxisHasZeroLength;
550
551  int                 CalculateTitleOffset;
552  int                 CalculateLabelOffset;
553
554  // Description:
555  // Use xy-axis only when Use2DMode=1:
556  int                 Use2DMode;
557
558  // Description:
559  // Vertical offset in display coordinates for X axis title (used in 2D mode only)
560  // Default: -40
561  double              VerticalOffsetXTitle2D;
562
563  // Description:
564  // Vertical offset in display coordinates for X axis title (used in 2D mode only)
565  // Default: -50
566  double              HorizontalOffsetYTitle2D;
567
568  // Description:
569  // Save title position (used in 2D mode only):
570  // val = 0 : no need to save position (doesn't stick actors in a position)
571  // val = 1 : positions have to be saved during the next render pass
572  // val = 2 : positions are saved; use them
573  int                 SaveTitlePosition;
574
575  // Description:
576  // Constant position for the title (used in 2D mode only)
577  double              TitleConstantPosition[2];
578
579  // Description:
580  // True if the 2D title has to be built, false otherwise
581  bool                NeedBuild2D;
582
583  double              LastMinDisplayCoordinate[3];
584  double              LastMaxDisplayCoordinate[3];
585};
586
587
588#endif
Note: See TracBrowser for help on using the repository browser.