vtkAxisActor.h 17.3 KB
Newer Older
1
2
/*=========================================================================

3
4
5
6
7
8
Program:   Visualization Toolkit
Module:    vtkAxisActor.h
Language:  C++
Date:      $Date$
Version:   $Revision$
Thanks:    Kathleen Bonnell, B Division, Lawrence Livermore Nat'l Laboratory
9

10
Copyright (c) 1993-2000 Ken Martin, Will Schroeder, Bill Lorensen
11
All rights reserved.
12
13
14
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notice for more information.
15
16
17
18
19
20
=========================================================================*/
// .NAME vtkAxisActor - Create an axis with tick marks and labels
// .SECTION Description
// vtkAxisActor creates an axis with tick marks, labels, and/or a title,
// depending on the particular instance variable settings. It is assumed that
// the axes is part of a bounding box and is orthoganal to one of the
21
22
23
// coordinate axes.  To use this class, you typically specify two points
// defining the start and end points of the line (xyz definition using
// vtkCoordinate class), the axis type (X, Y or Z), the axis location in
24
25
26
27
// relation to the bounding box, the bounding box, the number of labels, and
// the data range (min,max). You can also control what parts of the axis are
// visible including the line, the tick marks, the labels, and the title. It
// is also possible to control gridlines, and specifiy on which 'side' the
28
// tickmarks are drawn (again with respect to the underlying assumed
29
30
// bounding box). You can also specify the label format (a printf style format).
//
31
32
// This class decides how to locate the labels, and how to create reasonable
// tick marks and labels.
33
34
35
36
37
38
//
// Labels follow the camera so as to be legible from any viewpoint.
//
// The instance variables Point1 and Point2 are instances of vtkCoordinate.
// All calculations and references are in World Coordinates.
//
39
// .SECTION Thanks
40
// This class was written by:
41
// Hank Childs, Kathleen Bonnell, Amy Squillacote, Brad Whitlock,
42
43
44
// Eric Brugger, Claire Guilbaud, Nicolas Dolegieviez, Will Schroeder, 
// Karthik Krishnan, Aashish Chaudhary, Philippe Pbay, David Gobbi, 
// David Partyka, Utkarsh Ayachit David Cole, Franois Bertel, and Mark Olesen
45
// 
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// .SECTION See Also
// vtkActor vtkVectorText vtkPolyDataMapper vtkAxisActor2D vtkCoordinate

#ifndef __vtkAxisActor_h
#define __vtkAxisActor_h

#include "vtkActor.h"

#define VTK_MAX_LABELS    200
#define VTK_MAX_TICKS     1000

#define VTK_AXIS_TYPE_X   0
#define VTK_AXIS_TYPE_Y   1
#define VTK_AXIS_TYPE_Z   2

#define VTK_TICKS_INSIDE  0
#define VTK_TICKS_OUTSIDE 1
#define VTK_TICKS_BOTH    2

#define VTK_AXIS_POS_MINMIN 0
#define VTK_AXIS_POS_MINMAX 1
#define VTK_AXIS_POS_MAXMAX 2
#define VTK_AXIS_POS_MAXMIN 3

Aashish Chaudhary's avatar
Aashish Chaudhary committed
70
class vtkAxisFollower;
71
72
73
class vtkCamera;
class vtkCoordinate;
class vtkFollower;
74
class vtkFreeTypeUtilities;
75
76
77
class vtkPoints;
class vtkPolyData;
class vtkPolyDataMapper;
78
class vtkProperty2D;
79
class vtkStringArray;
80
class vtkTextActor;
81
class vtkTextProperty;
82
83
84
85
class vtkVectorText;

class VTK_HYBRID_EXPORT vtkAxisActor : public vtkActor
{
86
 public:
87
  vtkTypeMacro(vtkAxisActor,vtkActor);
88
89
90
91
92
  void PrintSelf(ostream& os, vtkIndent indent);

  // Description:
  // Instantiate object.
  static vtkAxisActor *New();
93

94
95
96
97
  // Description:
  // Specify the position of the first point defining the axis.
  virtual vtkCoordinate *GetPoint1Coordinate();
  virtual void SetPoint1(double x[3])
98
  { this->SetPoint1(x[0], x[1], x[2]); }
99
100
101
102
103
104
105
  virtual void SetPoint1(double x, double y, double z);
  virtual double *GetPoint1();

  // Description:
  // Specify the position of the second point defining the axis.
  virtual vtkCoordinate *GetPoint2Coordinate();
  virtual void SetPoint2(double x[3])
106
  { this->SetPoint2(x[0], x[1], x[2]); }
107
108
109
110
111
112
113
114
115
116
  virtual void SetPoint2(double x, double y, double z);
  virtual double *GetPoint2();

  // Description:
  // Specify the (min,max) axis range. This will be used in the generation
  // of labels, if labels are visible.
  vtkSetVector2Macro(Range,double);
  vtkGetVectorMacro(Range,double,2);

  // Description:
117
  // Set or get the bounds for this Actor as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
118
  void   SetBounds(double bounds[6]);
119
  void   SetBounds(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax);
120
121
122
  double *GetBounds(void);
  void   GetBounds(double bounds[6]);

123
  // Description:
124
125
126
127
128
  // Set/Get the format with which to print the labels on the axis.
  vtkSetStringMacro(LabelFormat);
  vtkGetStringMacro(LabelFormat);

  // Description:
129
  // Set/Get the flag that controls whether the minor ticks are visible.
130
131
132
133
134
135
136
137
138
139
140
  vtkSetMacro(MinorTicksVisible, int);
  vtkGetMacro(MinorTicksVisible, int);
  vtkBooleanMacro(MinorTicksVisible, int);


  // Description:
  // Set/Get the title of the axis actor,
  void SetTitle(const char *t);
  vtkGetStringMacro(Title);

  // Description:
141
  // Set/Get the size of the major tick marks
142
143
  vtkSetMacro(MajorTickSize, double);
  vtkGetMacro(MajorTickSize, double);
144

145
  // Description:
146
  // Set/Get the size of the major tick marks
147
148
149
150
151
152
153
154
155
  vtkSetMacro(MinorTickSize, double);
  vtkGetMacro(MinorTickSize, double);

  // Description:
  // Set/Get the location of the ticks.
  vtkSetClampMacro(TickLocation, int, VTK_TICKS_INSIDE, VTK_TICKS_BOTH);
  vtkGetMacro(TickLocation, int);

  void SetTickLocationToInside(void)
156
  { this->SetTickLocation(VTK_TICKS_INSIDE); };
157
  void SetTickLocationToOutside(void)
158
  { this->SetTickLocation(VTK_TICKS_OUTSIDE); };
159
  void SetTickLocationToBoth(void)
160
  { this->SetTickLocation(VTK_TICKS_BOTH); };
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
  // Description:
  // Set/Get visibility of the axis line.
  vtkSetMacro(AxisVisibility, int);
  vtkGetMacro(AxisVisibility, int);
  vtkBooleanMacro(AxisVisibility, int);

  // Description:
  // Set/Get visibility of the axis tick marks.
  vtkSetMacro(TickVisibility, int);
  vtkGetMacro(TickVisibility, int);
  vtkBooleanMacro(TickVisibility, int);

  // Description:
  // Set/Get visibility of the axis labels.
  vtkSetMacro(LabelVisibility, int);
  vtkGetMacro(LabelVisibility, int);
  vtkBooleanMacro(LabelVisibility, int);

  // Description:
  // Set/Get visibility of the axis title.
  vtkSetMacro(TitleVisibility, int);
  vtkGetMacro(TitleVisibility, int);
  vtkBooleanMacro(TitleVisibility, int);

186
  // Description:
187
188
189
  // Set/Get the axis title text property. 
  virtual void SetTitleTextProperty(vtkTextProperty *p);
  vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
190
191

  // Description:
192
193
194
195
  // Set/Get the axis labels text property.
  virtual void SetLabelTextProperty(vtkTextProperty *p);
  vtkGetObjectMacro(LabelTextProperty,vtkTextProperty);
  
196
197
198
199
200
201
  // Description:
  // Get/Set axis actor property (axis and its ticks)
  void SetAxisLinesProperty(vtkProperty *);
  vtkProperty* GetAxisLinesProperty();

  // Description:
202
  // Get/Set gridlines actor property (outer grid lines)
203
204
205
  void SetGridlinesProperty(vtkProperty *);
  vtkProperty* GetGridlinesProperty();

206
207
208
209
210
  // Description:
  // Get/Set inner gridlines actor property
  void SetInnerGridlinesProperty(vtkProperty *);
  vtkProperty* GetInnerGridlinesProperty();

211
212
213
214
215
  // Description:
  // Get/Set gridPolys actor property (grid quads)
  void SetGridpolysProperty(vtkProperty *);
  vtkProperty* GetGridpolysProperty();

216
217
218
219
220
221
  // Description:
  // Set/Get whether gridlines should be drawn.
  vtkSetMacro(DrawGridlines, int);
  vtkGetMacro(DrawGridlines, int);
  vtkBooleanMacro(DrawGridlines, int);

222
223
224
225
226
227
  // Description:
  // Set/Get whether inner gridlines should be drawn.
  vtkSetMacro(DrawInnerGridlines, int);
  vtkGetMacro(DrawInnerGridlines, int);
  vtkBooleanMacro(DrawInnerGridlines, int);

228
  // Description:
229
  // Set/Get the length to use when drawing gridlines.
230
231
232
233
234
235
236
  vtkSetMacro(GridlineXLength, double);
  vtkGetMacro(GridlineXLength, double);
  vtkSetMacro(GridlineYLength, double);
  vtkGetMacro(GridlineYLength, double);
  vtkSetMacro(GridlineZLength, double);
  vtkGetMacro(GridlineZLength, double);

237
238
239
240
241
242
  // Description:
  // Set/Get whether gridpolys should be drawn.
  vtkSetMacro(DrawGridpolys, int);
  vtkGetMacro(DrawGridpolys, int);
  vtkBooleanMacro(DrawGridpolys, int);

243
244
245
246
247
248
249
250
251
252
253
  // Description:
  // Set/Get the type of this axis.
  vtkSetClampMacro(AxisType, int, VTK_AXIS_TYPE_X, VTK_AXIS_TYPE_Z);
  vtkGetMacro(AxisType, int);
  void SetAxisTypeToX(void) { this->SetAxisType(VTK_AXIS_TYPE_X); };
  void SetAxisTypeToY(void) { this->SetAxisType(VTK_AXIS_TYPE_Y); };
  void SetAxisTypeToZ(void) { this->SetAxisType(VTK_AXIS_TYPE_Z); };

  // Description:
  // Set/Get the position of this axis (in relation to an an
  // assumed bounding box).  For an x-type axis, MINMIN corresponds
254
255
  // to the x-edge in the bounding box where Y values are minimum and
  // Z values are minimum. For a y-type axis, MAXMIN corresponds to the
256
  // y-edge where X values are maximum and Z values are minimum.
257
  //
258
259
260
261
  vtkSetClampMacro(AxisPosition, int, VTK_AXIS_POS_MINMIN, VTK_AXIS_POS_MAXMIN);
  vtkGetMacro(AxisPosition, int);

  void SetAxisPositionToMinMin(void)
262
  { this->SetAxisPosition(VTK_AXIS_POS_MINMIN); };
263
  void SetAxisPositionToMinMax(void)
264
  { this->SetAxisPosition(VTK_AXIS_POS_MINMAX); };
265
  void SetAxisPositionToMaxMax(void)
266
  { this->SetAxisPosition(VTK_AXIS_POS_MAXMAX); };
267
  void SetAxisPositionToMaxMin(void)
268
  { this->SetAxisPosition(VTK_AXIS_POS_MAXMIN); };
269
270
271
272
273
274
275
276

  // Description:
  // Set/Get the camera for this axis.  The camera is used by the
  // labels to 'follow' the camera and be legible from any viewpoint.
  virtual void SetCamera(vtkCamera*);
  vtkGetObjectMacro(Camera, vtkCamera);

  // Description:
277
  // Draw the axis.
278
  virtual int RenderOpaqueGeometry(vtkViewport* viewport);
279
280
281
282
  virtual int RenderTranslucentGeometry(vtkViewport* viewport);
  virtual int RenderTranslucentPolygonalGeometry(vtkViewport* viewport);
  virtual int RenderOverlay(vtkViewport* viewport);
  int HasTranslucentPolygonalGeometry();
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298

  // Description:
  // Release any graphics resources that are being consumed by this actor.
  // The parameter window could be used to determine which graphic
  // resources to release.
  void ReleaseGraphicsResources(vtkWindow *);

//BTX
  double ComputeMaxLabelLength(const double [3]);
  double ComputeTitleLength(const double [3]);
//ETX
  void SetLabelScale(const double);
  void SetTitleScale(const double);

  // Description:
  // Set/Get the starting position for minor and major tick points,
299
  // and the delta values that determine their spacing.
300
301
  vtkSetMacro(MinorStart, double);
  vtkGetMacro(MinorStart, double);
302
303
304
305
  double GetMajorStart(int axis);
  void SetMajorStart(int axis,double value);
  //vtkSetMacro(MajorStart, double);
  //vtkGetMacro(MajorStart, double);
306
307
  vtkSetMacro(DeltaMinor, double);
  vtkGetMacro(DeltaMinor, double);
308
309
310
311
  double GetDeltaMajor(int axis);
  void SetDeltaMajor(int axis,double value);
  //vtkSetMacro(DeltaMajor, double);
  //vtkGetMacro(DeltaMajor, double);
312

313
314
315
316
317
318
319
320
321
322
323
324
325
326
  // Description:
  // Set/Get the starting position for minor and major tick points on
  // the range and the delta values that determine their spacing. The
  // range and the position need not be identical. ie the displayed
  // values need not match the actual positions in 3D space.
  vtkSetMacro(MinorRangeStart, double);
  vtkGetMacro(MinorRangeStart, double);
  vtkSetMacro(MajorRangeStart, double);
  vtkGetMacro(MajorRangeStart, double);
  vtkSetMacro(DeltaRangeMinor, double);
  vtkGetMacro(DeltaRangeMinor, double);
  vtkSetMacro(DeltaRangeMajor, double);
  vtkGetMacro(DeltaRangeMajor, double);

327
328
329
330
331
332
//BTX
  void SetLabels(vtkStringArray *labels);
//ETX

  void BuildAxis(vtkViewport *viewport, bool);

333
//BTX
334
335
336
  // Description:
  // Get title actor and it is responsible for drawing
  // title text.
Aashish Chaudhary's avatar
Aashish Chaudhary committed
337
  vtkGetObjectMacro(TitleActor,  vtkAxisFollower);
338

339
340
  // Description:
  // Get label actors responsigle for drawing label text.
Aashish Chaudhary's avatar
Aashish Chaudhary committed
341
  inline vtkAxisFollower** GetLabelActors()
342
343
344
345
346
    {
    return this->LabelActors;
    }
//ETX

347
348
349
  // Description:
  // Get total numbe of labels built. Once built
  // this count does not change.
350
351
  vtkGetMacro(NumberOfLabelsBuilt, int);

352
  // Description:
353
354
355
356
357
358
  // Set/Get flag whether to calculate title offset.
  // Default is true.
  vtkSetMacro(CalculateTitleOffset, int);
  vtkGetMacro(CalculateTitleOffset, int);
  vtkBooleanMacro(CalculateTitleOffset, int);

359
  // Description:
360
361
362
363
364
365
  // Set/Get flag whether to calculate label offset.
  // Default is true.
  vtkSetMacro(CalculateLabelOffset, int);
  vtkGetMacro(CalculateLabelOffset, int);
  vtkBooleanMacro(CalculateLabelOffset, int);

366
367
368
369
  // Description:
  // Set/Get the 2D mode
  vtkSetMacro(Use2DMode, int);
  vtkGetMacro(Use2DMode, int);
370

371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
  // Description:
  // Set/Get the 2D mode the vertical offset for X title in 2D mode
  vtkSetMacro(VerticalOffsetXTitle2D, double);
  vtkGetMacro(VerticalOffsetXTitle2D, double);
  
  // Description:
  // Set/Get the 2D mode the horizontal offset for Y title in 2D mode
  vtkSetMacro(HorizontalOffsetYTitle2D, double);
  vtkGetMacro(HorizontalOffsetYTitle2D, double);
  
  // Description:
  // Set/Get whether title position must be saved in 2D mode
  vtkSetMacro(SaveTitlePosition, int);
  vtkGetMacro(SaveTitlePosition, int);
  
 protected:
387
388
389
390
391
392
393
394
395
396
397
  vtkAxisActor();
  ~vtkAxisActor();

  char  *Title;
  double  Range[2];
  double  LastRange[2];
  char  *LabelFormat;
  int    NumberOfLabelsBuilt;
  int    MinorTicksVisible;
  int    LastMinorTicksVisible;
  int    TickLocation;
398

399
400
401
402
403
  int    DrawGridlines;
  int    LastDrawGridlines;
  double  GridlineXLength;
  double  GridlineYLength;
  double  GridlineZLength;
404

405
406
407
  int    DrawInnerGridlines;
  int    LastDrawInnerGridlines;
  
408
409
410
  int    DrawGridpolys;
  int    LastDrawGridpolys;
  
411
412
413
414
415
  int    AxisVisibility;
  int    TickVisibility;
  int    LastTickVisibility;
  int    LabelVisibility;
  int    TitleVisibility;
416

417
418
419
  int    AxisType;
  int    AxisPosition;
  double  Bounds[6];
420

421
 private:
422
423
  vtkAxisActor(const vtkAxisActor&); // Not implemented
  void operator=(const vtkAxisActor&); // Not implemented
424
425
426
427

  void TransformBounds(vtkViewport *, double bnds[6]);

  void BuildLabels(vtkViewport *, bool);
428
  void BuildLabels2D(vtkViewport *, bool);
429
  void SetLabelPositions(vtkViewport *, bool);
430
  void SetLabelPositions2D(vtkViewport *, bool);
431
432

  void BuildTitle(bool);
433
  void BuildTitle2D(vtkViewport *viewport, bool);
434
435
436
437
438
439
440

  void SetAxisPointsAndLines(void);
  bool BuildTickPointsForXType(double p1[3], double p2[3], bool);
  bool BuildTickPointsForYType(double p1[3], double p2[3], bool);
  bool BuildTickPointsForZType(double p1[3], double p2[3], bool);

  bool TickVisibilityChanged(void);
441
442
443
  vtkProperty *NewTitleProperty();
  vtkProperty2D *NewTitleProperty2D();
  vtkProperty *NewLabelProperty();
444

445
446
  bool BoundsDisplayCoordinateChanged(vtkViewport *viewport);

447
448
449
450
451
452
  vtkCoordinate *Point1Coordinate;
  vtkCoordinate *Point2Coordinate;

  double  MajorTickSize;
  double  MinorTickSize;

453
454
455
  // For each axis (for the inner gridline generation)
  double  MajorStart[3];
  double  DeltaMajor[3];
456
457
458
  double  MinorStart;
  double  DeltaMinor;

459
460
461
462
463
464
  // For the ticks, w.r.t to the set range
  double  MajorRangeStart;
  double  MinorRangeStart;
  double  DeltaRangeMinor;
  double  DeltaRangeMajor;

465
466
467
  int    LastAxisPosition;
  int    LastAxisType;
  int    LastTickLocation;
Aashish Chaudhary's avatar
Aashish Chaudhary committed
468
  double LastLabelStart;
469
470
471
472

  vtkPoints         *MinorTickPts;
  vtkPoints         *MajorTickPts;
  vtkPoints         *GridlinePts;
473
474
  vtkPoints         *InnerGridlinePts;
  vtkPoints         *GridpolyPts;
475
476
477

  vtkVectorText     *TitleVector;
  vtkPolyDataMapper *TitleMapper;
Aashish Chaudhary's avatar
Aashish Chaudhary committed
478
  vtkAxisFollower   *TitleActor;
479
  vtkTextActor      *TitleActor2D;
480
  vtkTextProperty   *TitleTextProperty;
481
482
483

  vtkVectorText     **LabelVectors;
  vtkPolyDataMapper **LabelMappers;
Aashish Chaudhary's avatar
Aashish Chaudhary committed
484
  vtkAxisFollower   **LabelActors;
485
  vtkTextActor      **LabelActors2D;
486
  vtkTextProperty    *LabelTextProperty;
487

488
489
490
  vtkPolyData        *AxisLines;
  vtkPolyDataMapper  *AxisLinesMapper;
  vtkActor           *AxisLinesActor;
491
492
493
494
495
496
497
498
499
  vtkPolyData        *Gridlines;
  vtkPolyDataMapper  *GridlinesMapper;
  vtkActor           *GridlinesActor;
  vtkPolyData        *InnerGridlines;
  vtkPolyDataMapper  *InnerGridlinesMapper;
  vtkActor           *InnerGridlinesActor;
  vtkPolyData        *Gridpolys;
  vtkPolyDataMapper  *GridpolysMapper;
  vtkActor           *GridpolysActor;
500
501
502
503
504
505
506
507

  vtkCamera          *Camera;
  vtkTimeStamp        BuildTime;
  vtkTimeStamp        BoundsTime;
  vtkTimeStamp        LabelBuildTime;
  vtkTimeStamp        TitleTextTime;

  int                 AxisHasZeroLength;
508
509
510

  int                 CalculateTitleOffset;
  int                 CalculateLabelOffset;
511
512
513

  // Description: 
  // Use xy-axis only when Use2DMode=1:
514
  int                 Use2DMode;
515
516

  // Description:
517
518
519
520
521
522
  // Vertical offset in display coordinates for X axis title (used in 2D mode only)
  // Default: -40
  double              VerticalOffsetXTitle2D;

  // Description:
  // Vertical offset in display coordinates for X axis title (used in 2D mode only)
523
  // Default: -50
524
525
526
527
  double              HorizontalOffsetYTitle2D;

  // Description:
  // Save title position (used in 2D mode only):
528
529
  // val = 0 : no need to save position (doesn't stick actors in a position)
  // val = 1 : positions have to be saved during the next render pass
530
  // val = 2 : positions are saved; use them
531
  int		      SaveTitlePosition;
532
533

  // Description:
534
  // Constant position for the title (used in 2D mode only)
535
  double	      TitleConstantPosition[2];
536
537
538

  // Description:
  // True if the 2D title has to be built, false otherwise
539
  bool                NeedBuild2D;
540

541
542
  double	      LastMinDisplayCoordinate[3];
  double	      LastMaxDisplayCoordinate[3];
543
544
545

  // Description:
  // FreeType library utility
546
  vtkFreeTypeUtilities *FreeTypeUtilities;
547
548
549
550
};


#endif