vtkCubeAxesActor.h 17.4 KB
Newer Older
1
2
3
4
5
6
7
/*=========================================================================

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

10
11
Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserve
12
13
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

14
15
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16
17
     PURPOSE.  See the above copyright notice for more information.
=========================================================================*/
18
// .NAME vtkCubeAxesActor - create a  plot of a bounding box edges -
19
20
// used for navigation
// .SECTION Description
21
// vtkCubeAxesActor is a composite actor that draws axes of the
22
23
24
25
// bounding box of an input dataset. The axes include labels and titles
// for the x-y-z axes. The algorithm selects which axes to draw based
// on the user-defined 'fly' mode.  (STATIC is default).
// 'STATIC' constructs axes from all edges of the bounding box.
26
27
28
29
30
31
32
33
// 'CLOSEST_TRIAD' consists of the three axes x-y-z forming a triad that
// lies closest to the specified camera.
// 'FURTHEST_TRIAD' consists of the three axes x-y-z forming a triad that
// lies furthest from the specified camera.
// 'OUTER_EDGES' is constructed from edges that are on the "exterior" of the
// bounding box, exterior as determined from examining outer edges of the
// bounding box in projection (display) space.
//
34
35
36
// To use this object you must define a bounding box and the camera used
// to render the vtkCubeAxesActor. You can optionally turn on/off labels,
// ticks, gridlines, and set tick location, number of labels, and text to
37
// use for axis-titles.  A 'corner offset' can also be set.  This allows
38
39
40
41
42
// the axes to be set partially away from the actual bounding box to perhaps
// prevent overlap of labels between the various axes.
//
// The Bounds instance variable (an array of six doubles) is used to determine
// the bounding box.
43
//
44
45
46
47
48
49
50
51
52
// .SECTION Thanks
// This class was written by:
// Hank Childs, Kathleen Bonnell, Amy Squillacote, Brad Whitlock,
// Eric Brugger, Claire Guilbaud, Nicolas Dolegieviez, Will Schroeder, 
// Aashish Chaudhary, Philippe Pébay, David Gobbi, David Partyka, Utkarsh Ayachit
// David Cole, François Bertel, and Mark Olesen
// 
//
// .section See Also
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// vtkActor vtkAxisActor vtkCubeAxesActor2D

#ifndef __vtkCubeAxesActor_h
#define __vtkCubeAxesActor_h

#define VTK_FLY_OUTER_EDGES     0
#define VTK_FLY_CLOSEST_TRIAD   1
#define VTK_FLY_FURTHEST_TRIAD  2
#define VTK_FLY_STATIC_TRIAD    3
#define VTK_FLY_STATIC_EDGES    4

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

68
69
#define NUMBER_OF_ALIGNED_AXIS 4

70
71
72
73
#include "vtkActor.h"

class vtkAxisActor;
class vtkCamera;
Philippe Pébay's avatar
Philippe Pébay committed
74
class vtkTextProperty;
75
76
77
78

class VTK_HYBRID_EXPORT vtkCubeAxesActor : public vtkActor
{
public:
79
  vtkTypeMacro(vtkCubeAxesActor,vtkActor);
80
81
82
  void PrintSelf(ostream& os, vtkIndent indent);

  // Description:
83
  // Instantiate object with label format "6.3g" and the number of labels
84
85
  // per axis set to 3.
  static vtkCubeAxesActor *New();
86

87
88
89
  // Description:
  // Draw the axes as per the vtkProp superclass' API.
  virtual int RenderOpaqueGeometry(vtkViewport*);
90
91
92
93
  virtual int RenderTranslucentGeometry(vtkViewport*);
  virtual int RenderTranslucentPolygonalGeometry(vtkViewport*);
  virtual int RenderOverlay(vtkViewport*);
  int HasTranslucentPolygonalGeometry();
94

95
96
  // Description:
  // Gets/Sets the RebuildAxes flag
97
98
  vtkSetMacro( RebuildAxes, bool );
  vtkGetMacro( RebuildAxes, bool );
99

100
101
102
103
104
105
106
  // Description:
  // Explicitly specify the region in space around which to draw the bounds.
  // The bounds is used only when no Input or Prop is specified. The bounds
  // are specified according to (xmin,xmax, ymin,ymax, zmin,zmax), making
  // sure that the min's are less than the max's.
  vtkSetVector6Macro(Bounds,double);
  double *GetBounds();
107
  void GetBounds(double& xmin, double& xmax, double& ymin, double& ymax,
108
109
110
111
                 double& zmin, double& zmax);
  void GetBounds(double bounds[6]);

  // Description:
112
113
114
115
116
117
118
119
120
121
122
123
124
  // Explicitly specify the range of each axes that's used to define the prop.
  // The default, (if you do not use these methods) is to use the bounds
  // specified, or use the bounds of the Input Prop if one is specified. This
  // method allows you to separate the notion of extent of the axes in physical
  // space (bounds) and the extent of the values it represents. In other words,
  // you can have the ticks and labels show a different range.
  vtkSetVector2Macro( XAxisRange, double );
  vtkSetVector2Macro( YAxisRange, double );
  vtkSetVector2Macro( ZAxisRange, double );
  vtkGetVector2Macro( XAxisRange, double );
  vtkGetVector2Macro( YAxisRange, double );
  vtkGetVector2Macro( ZAxisRange, double );

125
126
127
128
  // Description:
  // Explicitly specify the screen size of title and label text.
  // ScreenSize detemines the size of the text in terms of screen
  // pixels. Default is 10.0.
129
  void SetScreenSize(double screenSize);
130
131
  vtkGetMacro(ScreenSize, double);

132
133
  // Description:
  // Set/Get the camera to perform scaling and translation of the
134
135
136
137
138
  // vtkCubeAxesActor.
  virtual void SetCamera(vtkCamera*);
  vtkGetObjectMacro(Camera,vtkCamera);

  // Description:
139
140
  // Specify a mode to control how the axes are drawn: either static,
  // closest triad, furthest triad or outer edges in relation to the
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  // camera position.
  vtkSetClampMacro(FlyMode, int, VTK_FLY_OUTER_EDGES, VTK_FLY_STATIC_EDGES);
  vtkGetMacro(FlyMode, int);
  void SetFlyModeToOuterEdges()
    {this->SetFlyMode(VTK_FLY_OUTER_EDGES);};
  void SetFlyModeToClosestTriad()
    {this->SetFlyMode(VTK_FLY_CLOSEST_TRIAD);};
  void SetFlyModeToFurthestTriad()
    {this->SetFlyMode(VTK_FLY_FURTHEST_TRIAD);};
  void SetFlyModeToStaticTriad()
    {this->SetFlyMode(VTK_FLY_STATIC_TRIAD);};
  void SetFlyModeToStaticEdges()
    {this->SetFlyMode(VTK_FLY_STATIC_EDGES);};

  // Description:
156
  // Set/Get the labels for the x, y, and z axes. By default,
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
  // use "X-Axis", "Y-Axis" and "Z-Axis".
  vtkSetStringMacro(XTitle);
  vtkGetStringMacro(XTitle);
  vtkSetStringMacro(XUnits);
  vtkGetStringMacro(XUnits);
  vtkSetStringMacro(YTitle);
  vtkGetStringMacro(YTitle);
  vtkSetStringMacro(YUnits);
  vtkGetStringMacro(YUnits);
  vtkSetStringMacro(ZTitle);
  vtkGetStringMacro(ZTitle);
  vtkSetStringMacro(ZUnits);
  vtkGetStringMacro(ZUnits);

  // Description:
  // Set/Get the format with which to print the labels on each of the
  // x-y-z axes.
  vtkSetStringMacro(XLabelFormat);
  vtkGetStringMacro(XLabelFormat);
  vtkSetStringMacro(YLabelFormat);
  vtkGetStringMacro(YLabelFormat);
  vtkSetStringMacro(ZLabelFormat);
  vtkGetStringMacro(ZLabelFormat);
180

181
182
  // Description:
  // Set/Get the inertial factor that controls how often (i.e, how
183
  // many renders) the axes can switch position (jump from one axes
184
185
186
187
188
189
  // to another).
  vtkSetClampMacro(Inertia, int, 1, VTK_LARGE_INTEGER);
  vtkGetMacro(Inertia, int);

  // Description:
  // Specify an offset value to "pull back" the axes from the corner at
190
  // which they are joined to avoid overlap of axes labels. The
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
  // "CornerOffset" is the fraction of the axis length to pull back.
  vtkSetMacro(CornerOffset, double);
  vtkGetMacro(CornerOffset, double);

  // 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 *);

  // Description:
  // Turn on and off the visibility of each axis.
  vtkSetMacro(XAxisVisibility,int);
  vtkGetMacro(XAxisVisibility,int);
  vtkBooleanMacro(XAxisVisibility,int);
  vtkSetMacro(YAxisVisibility,int);
  vtkGetMacro(YAxisVisibility,int);
  vtkBooleanMacro(YAxisVisibility,int);
  vtkSetMacro(ZAxisVisibility,int);
  vtkGetMacro(ZAxisVisibility,int);
  vtkBooleanMacro(ZAxisVisibility,int);

  // Description:
  // Turn on and off the visibility of labels for each axis.
  vtkSetMacro(XAxisLabelVisibility,int);
  vtkGetMacro(XAxisLabelVisibility,int);
  vtkBooleanMacro(XAxisLabelVisibility,int);

  vtkSetMacro(YAxisLabelVisibility,int);
  vtkGetMacro(YAxisLabelVisibility,int);
  vtkBooleanMacro(YAxisLabelVisibility,int);

  vtkSetMacro(ZAxisLabelVisibility,int);
  vtkGetMacro(ZAxisLabelVisibility,int);
  vtkBooleanMacro(ZAxisLabelVisibility,int);

  // Description:
  // Turn on and off the visibility of ticks for each axis.
  vtkSetMacro(XAxisTickVisibility,int);
  vtkGetMacro(XAxisTickVisibility,int);
  vtkBooleanMacro(XAxisTickVisibility,int);

  vtkSetMacro(YAxisTickVisibility,int);
  vtkGetMacro(YAxisTickVisibility,int);
  vtkBooleanMacro(YAxisTickVisibility,int);

  vtkSetMacro(ZAxisTickVisibility,int);
  vtkGetMacro(ZAxisTickVisibility,int);
  vtkBooleanMacro(ZAxisTickVisibility,int);

  // Description:
  // Turn on and off the visibility of minor ticks for each axis.
  vtkSetMacro(XAxisMinorTickVisibility,int);
  vtkGetMacro(XAxisMinorTickVisibility,int);
  vtkBooleanMacro(XAxisMinorTickVisibility,int);

  vtkSetMacro(YAxisMinorTickVisibility,int);
  vtkGetMacro(YAxisMinorTickVisibility,int);
  vtkBooleanMacro(YAxisMinorTickVisibility,int);

  vtkSetMacro(ZAxisMinorTickVisibility,int);
  vtkGetMacro(ZAxisMinorTickVisibility,int);
  vtkBooleanMacro(ZAxisMinorTickVisibility,int);

  vtkSetMacro(DrawXGridlines,int);
  vtkGetMacro(DrawXGridlines,int);
  vtkBooleanMacro(DrawXGridlines,int);

  vtkSetMacro(DrawYGridlines,int);
  vtkGetMacro(DrawYGridlines,int);
  vtkBooleanMacro(DrawYGridlines,int);

  vtkSetMacro(DrawZGridlines,int);
  vtkGetMacro(DrawZGridlines,int);
  vtkBooleanMacro(DrawZGridlines,int);

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
  vtkSetMacro(DrawXInnerGridlines,int);
  vtkGetMacro(DrawXInnerGridlines,int);
  vtkBooleanMacro(DrawXInnerGridlines,int);

  vtkSetMacro(DrawYInnerGridlines,int);
  vtkGetMacro(DrawYInnerGridlines,int);
  vtkBooleanMacro(DrawYInnerGridlines,int);

  vtkSetMacro(DrawZInnerGridlines,int);
  vtkGetMacro(DrawZInnerGridlines,int);
  vtkBooleanMacro(DrawZInnerGridlines,int);

  vtkSetMacro(DrawXGridpolys,int);
  vtkGetMacro(DrawXGridpolys,int);
  vtkBooleanMacro(DrawXGridpolys,int);

  vtkSetMacro(DrawYGridpolys,int);
  vtkGetMacro(DrawYGridpolys,int);
  vtkBooleanMacro(DrawYGridpolys,int);

  vtkSetMacro(DrawZGridpolys,int);
  vtkGetMacro(DrawZGridpolys,int);
  vtkBooleanMacro(DrawZGridpolys,int);

291
292
293
294
295
296
297
298
  // Description:
  // Returns the text property for the title on an axis.
  vtkTextProperty *GetTitleTextProperty(int);

  // Description:
  // Returns the text property for the labels on an axis.
  vtkTextProperty *GetLabelTextProperty(int);

299
300
301
302
303
304
305
306
307
308
  // Description:
  // Get/Set axes actors properties.
  void SetXAxesLinesProperty(vtkProperty *);
  vtkProperty* GetXAxesLinesProperty();
  void SetYAxesLinesProperty(vtkProperty *);
  vtkProperty* GetYAxesLinesProperty();
  void SetZAxesLinesProperty(vtkProperty *);
  vtkProperty* GetZAxesLinesProperty();

  // Description:
309
  // Get/Set axes (outer) gridlines actors properties.
310
311
312
313
314
315
  void SetXAxesGridlinesProperty(vtkProperty *);
  vtkProperty* GetXAxesGridlinesProperty();
  void SetYAxesGridlinesProperty(vtkProperty *);
  vtkProperty* GetYAxesGridlinesProperty();
  void SetZAxesGridlinesProperty(vtkProperty *);
  vtkProperty* GetZAxesGridlinesProperty();
316
 
317
318
319
320
321
322
323
324
325
  // Description:
  // Get/Set axes inner gridlines actors properties.
  void SetXAxesInnerGridlinesProperty(vtkProperty *);
  vtkProperty* GetXAxesInnerGridlinesProperty();
  void SetYAxesInnerGridlinesProperty(vtkProperty *);
  vtkProperty* GetYAxesInnerGridlinesProperty();
  void SetZAxesInnerGridlinesProperty(vtkProperty *);
  vtkProperty* GetZAxesInnerGridlinesProperty();

326
327
328
329
330
331
332
333
334
  // Description:
  // Get/Set axes gridPolys actors properties.
  void SetXAxesGridpolysProperty(vtkProperty *);
  vtkProperty* GetXAxesGridpolysProperty();
  void SetYAxesGridpolysProperty(vtkProperty *);
  vtkProperty* GetYAxesGridpolysProperty();
  void SetZAxesGridpolysProperty(vtkProperty *);
  vtkProperty* GetZAxesGridpolysProperty();

335
  // Description:
336
  // Set/Get the location of ticks marks.
337
338
339
  vtkSetClampMacro(TickLocation, int, VTK_TICKS_INSIDE, VTK_TICKS_BOTH);
  vtkGetMacro(TickLocation, int);

340
  void SetTickLocationToInside(void)
341
    { this->SetTickLocation(VTK_TICKS_INSIDE); };
342
  void SetTickLocationToOutside(void)
343
    { this->SetTickLocation(VTK_TICKS_OUTSIDE); };
344
  void SetTickLocationToBoth(void)
345
346
    { this->SetTickLocation(VTK_TICKS_BOTH); };

347
  void SetLabelScaling(bool, int, int, int);
348
349
350
351
352
353
354
355

  //! use textactor if val = 1 (2D) instead of follower (3D - val = 0) for title 
  void SetUse2DMode( int val );
  //! return 1 if textactor is used
  int GetUse2DMode();
  //! for 2D axis only : during the next render, the axis positions have to be save for later use.
  void SetSaveTitlePosition( int val );
      
356
357
358
359
360
361
362
363
364
  // Description:
  // Shallow copy of a KatCubeAxesActor.
  void ShallowCopy(vtkCubeAxesActor *actor);

protected:
  vtkCubeAxesActor();
  ~vtkCubeAxesActor();

  int LabelExponent(double min, double max);
365

366
  int Digits(double min, double max);
367

368
369
  double MaxOf(double, double);
  double MaxOf(double, double, double, double);
370

371
372
373
  double FFix(double);
  double FSign(double, double);

374
375
376
  void UpdateLabels(vtkAxisActor **axis, int index);

  double Bounds[6]; //Define bounds explicitly
377
378

  vtkCamera *Camera;
379

380
  int FlyMode;
381

382
383
384
  // Description:
  // Control variables for all axes
  // NB: [0] always for 'Major' axis during non-static fly modes.
385
386
387
  vtkAxisActor *XAxes[NUMBER_OF_ALIGNED_AXIS];
  vtkAxisActor *YAxes[NUMBER_OF_ALIGNED_AXIS];
  vtkAxisActor *ZAxes[NUMBER_OF_ALIGNED_AXIS];
388

389
390
  bool RebuildAxes;

391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
  char *XTitle;
  char *XUnits;
  char *YTitle;
  char *YUnits;
  char *ZTitle;
  char *ZUnits;

  char *ActualXLabel;
  char *ActualYLabel;
  char *ActualZLabel;

  int TickLocation;

  int XAxisVisibility;
  int YAxisVisibility;
  int ZAxisVisibility;

  int XAxisTickVisibility;
  int YAxisTickVisibility;
  int ZAxisTickVisibility;

  int XAxisMinorTickVisibility;
  int YAxisMinorTickVisibility;
  int ZAxisMinorTickVisibility;

  int XAxisLabelVisibility;
  int YAxisLabelVisibility;
  int ZAxisLabelVisibility;

  int DrawXGridlines;
  int DrawYGridlines;
  int DrawZGridlines;

424
425
426
427
428
429
430
431
  int DrawXInnerGridlines;
  int DrawYInnerGridlines;
  int DrawZInnerGridlines;

  int DrawXGridpolys;
  int DrawYGridpolys;
  int DrawZGridpolys;

432
433
434
  char  *XLabelFormat;
  char  *YLabelFormat;
  char  *ZLabelFormat;
435

436
  double CornerOffset;
437

438
  int   Inertia;
439

440
  int   RenderCount;
441

442
  int   InertiaLocs[3];
443

444
  int RenderSomething;
445

Aashish Chaudhary's avatar
Aashish Chaudhary committed
446
447
  double LabelScreenOffset;
  double TitleScreenOffset;
448

449
450
451
  vtkTextProperty* TitleTextProperty[3];
  vtkTextProperty* LabelTextProperty[3];

452
453
454
455
456
457
  vtkProperty  *XAxesLinesProperty;
  vtkProperty  *YAxesLinesProperty;
  vtkProperty  *ZAxesLinesProperty;
  vtkProperty  *XAxesGridlinesProperty;
  vtkProperty  *YAxesGridlinesProperty;
  vtkProperty  *ZAxesGridlinesProperty;
458
459
460
  vtkProperty  *XAxesInnerGridlinesProperty;
  vtkProperty  *YAxesInnerGridlinesProperty;
  vtkProperty  *ZAxesInnerGridlinesProperty;
461
462
463
464
  vtkProperty  *XAxesGridpolysProperty;
  vtkProperty  *YAxesGridpolysProperty;
  vtkProperty  *ZAxesGridpolysProperty;

465
private:
466
467
  vtkCubeAxesActor(const vtkCubeAxesActor&); // Not implemented
  void operator=(const vtkCubeAxesActor&); // Not implemented
468
469
470
471
472
473
474
475
476

  vtkSetStringMacro(ActualXLabel);
  vtkSetStringMacro(ActualYLabel);
  vtkSetStringMacro(ActualZLabel);

  vtkTimeStamp BuildTime;
  int LastXPow;
  int LastYPow;
  int LastZPow;
477

478
479
480
  int UserXPow;
  int UserYPow;
  int UserZPow;
481

482
  bool AutoLabelScaling;
483

484
485
486
  int LastXAxisDigits;
  int LastYAxisDigits;
  int LastZAxisDigits;
487

488
489
490
491
  double LastXRange[2];
  double LastYRange[2];
  double LastZRange[2];

492
493
494
495
496
497
  int    LastFlyMode;

  int   RenderAxesX[NUMBER_OF_ALIGNED_AXIS];
  int   RenderAxesY[NUMBER_OF_ALIGNED_AXIS];
  int   RenderAxesZ[NUMBER_OF_ALIGNED_AXIS];

498
499
500
501
502
503
504
  int   NumberOfAxesX;
  int   NumberOfAxesY;
  int   NumberOfAxesZ;

  bool MustAdjustXValue;
  bool MustAdjustYValue;
  bool MustAdjustZValue;
505

506
507
508
509
  bool ForceXLabelReset;
  bool ForceYLabelReset;
  bool ForceZLabelReset;

510
511
512
513
  double XAxisRange[2];
  double YAxisRange[2];
  double ZAxisRange[2];

514
515
516
517
518
  double LabelScale;
  double TitleScale;

  double ScreenSize;

519
520
521
522
523
  // Description:
  // Major start and delta values, in each direction.
  // These values are needed for inner grid lines generation
  double MajorStart[3];
  double DeltaMajor[3];
524

525
  void  TransformBounds(vtkViewport *viewport, const double bounds[6],
526
527
                        double pts[8][3]);
  void  AdjustAxes(double bounds[6],
528
529
530
                   double xCoords[NUMBER_OF_ALIGNED_AXIS][6],
                   double yCoords[NUMBER_OF_ALIGNED_AXIS][6],
                   double zCoords[NUMBER_OF_ALIGNED_AXIS][6],
531
532
533
                   double xRange[2], double yRange[2], double zRange[2]);

  bool  ComputeTickSize(double bounds[6]);
534
535
536
  void  AdjustValues(const double xRange[2],
                     const double yRange[2],
                     const double zRange[2]);
537
538
539
540
  void  AdjustRange(const double bounds[6]);
  void  BuildAxes(vtkViewport *);
  void  DetermineRenderAxes(vtkViewport *);
  void  SetNonDependentAttributes(void);
541
542
  void  BuildLabels(vtkAxisActor *axes[NUMBER_OF_ALIGNED_AXIS]);
  void  AdjustTicksComputeRange(vtkAxisActor *axes[NUMBER_OF_ALIGNED_AXIS],
543
      double rangeMin, double rangeMax);
544

545
546
547
548
  void    AutoScale(vtkViewport *viewport);
  void    AutoScale(vtkViewport *viewport, vtkAxisActor *axes[NUMBER_OF_ALIGNED_AXIS]);
  double  AutoScale(vtkViewport *viewport, double screenSize, double position[3]);

549
550
551
552
553
  void ShallowCopy(vtkProp *prop) { this->vtkProp::ShallowCopy( prop ); };
};


#endif