vtkPolarAxesActor.cxx 32 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkPolarAxesActor.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     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.

 =========================================================================*/
#include "vtkPolarAxesActor.h"

17
#include "vtkArcSource.h"
18
19
20
#include "vtkAxisActor.h"
#include "vtkAxisFollower.h"
#include "vtkCamera.h"
21
#include "vtkCellArray.h"
22
23
24
25
#include "vtkCoordinate.h"
#include "vtkFollower.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
26
27
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
28
29
#include "vtkProperty.h"
#include "vtkStringArray.h"
30
#include "vtkTextProperty.h"
31
32
#include "vtkViewport.h"

33
#include <vtksys/ios/sstream>
34

35
#define VTK_POLAR_AXES_ACTOR_RTOL ( 1. - 10. * VTK_DBL_EPSILON )
36

37
38
vtkStandardNewMacro(vtkPolarAxesActor);
vtkCxxSetObjectMacro(vtkPolarAxesActor, Camera,vtkCamera);
39
40
vtkCxxSetObjectMacro(vtkPolarAxesActor,PolarAxisLabelTextProperty,vtkTextProperty);
vtkCxxSetObjectMacro(vtkPolarAxesActor,PolarAxisTitleTextProperty,vtkTextProperty);
41

Aashish Chaudhary's avatar
Aashish Chaudhary committed
42
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
43
void vtkPolarAxesActor::PrintSelf( ostream& os, vtkIndent indent )
44
{
Philippe Pébay's avatar
Philippe Pébay committed
45
  this->Superclass::PrintSelf( os,indent );
46

47
48
  os << indent << "Bounds: \n";
  os << indent << "  Xmin,Xmax: (" << this->Bounds[0] << ", "
49
     << this->Bounds[1] << ")\n";
50
  os << indent << "  Ymin,Ymax: (" << this->Bounds[2] << ", "
51
     << this->Bounds[3] << ")\n";
52
  os << indent << "  Zmin,Zmax: (" << this->Bounds[4] << ", "
53
     << this->Bounds[5] << ")\n";
54

55
  os << indent << "ScreenSize: " << this->ScreenSize << "\n";
Philippe Pébay's avatar
Philippe Pébay committed
56

57
58
  os << indent << "Number Of Radial Axes: " << this->NumberOfRadialAxes << endl;
  os << indent << "Number Of Polar Axis Ticks: " << this->NumberOfPolarAxisTicks << endl;
59
60
  os << indent << "Auto Subdivide Polar Axis: "
     << ( this->AutoSubdividePolarAxis ? "On\n" : "Off\n" );
61

Aashish Chaudhary's avatar
Aashish Chaudhary committed
62
  os << indent << "Pole: ("
63
64
     << this->Pole[0] << ", "
     << this->Pole[1] << ", "
65
     << this->Pole[2] << ")\n";
66

67
68
69
70
71
  os << indent << "Maximum Radius: " << this->MaximumRadius << endl;
  os << indent << "Auto-Scale Radius: " << this->AutoScaleRadius << endl;
  os << indent << "Minimum Angle: " << this->MinimumAngle << endl;
  os << indent << "Maximum Angle: " << this->MaximumAngle << endl;
  os << indent << "Smallest Visible Polar Angle: " << this->SmallestVisiblePolarAngle << endl;
Philippe Pébay's avatar
Philippe Pébay committed
72
73
  os << indent << "Radial Units (degrees): "
     << ( this->RadialUnits ? "On\n" : "Off\n" ) << endl;
74

Philippe Pébay's avatar
Philippe Pébay committed
75
  if ( this->Camera )
76
77
    {
    os << indent << "Camera:\n";
Philippe Pébay's avatar
Philippe Pébay committed
78
    this->Camera->PrintSelf( os,indent.GetNextIndent() );
79
80
81
82
83
84
    }
  else
    {
    os << indent << "Camera: (none)\n";
    }

Philippe Pébay's avatar
Philippe Pébay committed
85
86
  os << indent << "EnableDistanceLOD: "   
     << ( this->EnableDistanceLOD ? "On" : "Off" ) << endl;
87
  os << indent << "DistanceLODThreshold: "   << this->DistanceLODThreshold    << "\n";
Philippe Pébay's avatar
Philippe Pébay committed
88

89
90
  os << indent << "EnableViewAngleLOD: "   
     << ( this->EnableViewAngleLOD ? "On" : "Off" ) << endl;
91
  os << indent << "ViewAngleLODThreshold: "   << this->ViewAngleLODThreshold    << "\n";
92

Philippe Pébay's avatar
Philippe Pébay committed
93
  os << indent << "Polar Axis Title: " << this->PolarAxisTitle << "\n";
94
  os << indent << "Polar Label Format: " << this->PolarLabelFormat << "\n";
Philippe Pébay's avatar
Philippe Pébay committed
95
96
  os << indent << "PolarAxisLabelTextProperty: " << this->PolarAxisLabelTextProperty << endl;
  os << indent << "PolarAxisTitleTextProperty: " << this->PolarAxisTitleTextProperty << endl;
97
98
99
100
101
102
103
104
  os << indent << "Polar Axis Visibility: "
     << ( this->PolarAxisVisibility ? "On\n" : "Off\n" );
  os << indent << "Polar Title Visibility: "
     << ( this->PolarTitleVisibility ? "On" : "Off" ) << endl;
  os << indent << "Polar Label Visibility: "
     << ( this->PolarLabelVisibility ? "On" : "Off" ) << endl;
  os << indent << "Polar Tick Visibility: "
     << ( this->PolarTickVisibility ? "On" : "Off" ) << endl;
105
106

  os << indent << "Radial Axes Visibility: "
107
     << ( this->RadialAxesVisibility ? "On\n" : "Off\n" );
108
109
  os << indent << "Radial Title Visibility: "
     << ( this->RadialTitleVisibility ? "On" : "Off" ) << endl;
110

111

112
113
  os << indent << "Polar Arcs Visibility: "
     << ( this->PolarArcsVisibility ? "On" : "Off" ) << endl;
114
115
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
116
//-----------------------------------------------------------------------------
117
118
vtkPolarAxesActor::vtkPolarAxesActor() : vtkActor()
{
119
120
121
122
123
  // Default bounds
  this->Bounds[0] = -1.0; this->Bounds[1] = 1.0;
  this->Bounds[2] = -1.0; this->Bounds[3] = 1.0;
  this->Bounds[4] = -1.0; this->Bounds[5] = 1.0;

124
  // Default pole coordinates
125
126
127
  this->Pole[0] = 0.;
  this->Pole[1] = 0.;
  this->Pole[2] = 0.;
128

129
  // Default number of radial axes
130
  this->NumberOfRadialAxes = VTK_MAXIMUM_NUMBER_OF_RADIAL_AXES;
131

132
133
134
135
  // Invalid default number of polar arcs, and auto-calculate by default
  this->NumberOfPolarAxisTicks = -1;
  this->AutoSubdividePolarAxis = true;

136
  // Default maximum polar radius
137
  this->MaximumRadius = 1.;
138

139
140
141
  // Do not auto-scale radius by default
  this->AutoScaleRadius = false;

142
143
144
  // Default minimum polar angle
  this->MinimumAngle = 0.;

145
  // Default maximum polar angle
146
  this->MaximumAngle = 90.;
147

148
149
150
  // Default smallest radial angle distinguishable from polar axis
  this->SmallestVisiblePolarAngle = .5;

151
  // By default show angle units (degrees)
152
  this->RadialUnits = true;
153
154
155

  this->Camera = NULL;

156
  // Default text screen size
157
158
  this->ScreenSize = 10.0;

159
160
  // Screen offset for labels
  // Pivot point at center of the geometry hence this->ScreenSize * 0.5
Philippe Pébay's avatar
Philippe Pébay committed
161
  this->LabelScreenOffset = 15.0 + this->ScreenSize * 0.5;
162

163
  // Text properties of polar axis title and labels, with default color white
164
165
166
  // Properties of the radial axes, with default color black
  this->PolarAxisProperty = vtkProperty::New();
  this->PolarAxisProperty->SetColor( 0., 0., 0. );
Philippe Pébay's avatar
Philippe Pébay committed
167
  this->PolarAxisTitleTextProperty = vtkTextProperty::New();
168
  this->PolarAxisTitleTextProperty->SetColor( 1., 1. ,1. );
Philippe Pébay's avatar
Philippe Pébay committed
169
170
  this->PolarAxisTitleTextProperty->SetFontFamilyToArial();
  this->PolarAxisLabelTextProperty = vtkTextProperty::New();
171
  this->PolarAxisLabelTextProperty->SetColor( 1., 1. ,1. );
Philippe Pébay's avatar
Philippe Pébay committed
172
173
  this->PolarAxisLabelTextProperty->SetFontFamilyToArial();

174
175
176
177
178
179
180
181
182
183
  // Create and set polar axis of type X
  this->PolarAxis = vtkAxisActor::New();
  this->PolarAxis->SetAxisTypeToX();
  this->PolarAxis->SetAxisPositionToMinMax();
  this->PolarAxis->SetCalculateTitleOffset( 0 );
  this->PolarAxis->SetCalculateLabelOffset( 0 );

  // Base offset for followers
  double offset = this->LabelScreenOffset + this->ScreenSize * 0.5;

184
185
186
187
  // By default enable distance based LOD
  this->EnableDistanceLOD = 1;
  this->DistanceLODThreshold = .7;

188
189
190
191
  // By default enable view angle based LOD
  this->EnableViewAngleLOD = 1;
  this->ViewAngleLODThreshold = .3;

192
  // Set polar axis title follower (label followers not built yet)
193
194
195
  vtkAxisFollower* follower = this->PolarAxis->GetTitleActor();
  follower->SetAxis( this->PolarAxis );
  follower->SetScreenOffset( 2.0 * offset + 5 );
196
  follower->SetEnableDistanceLOD( this->EnableDistanceLOD );
197
198
199
  follower->SetDistanceLODThreshold( this->DistanceLODThreshold );
  follower->SetEnableViewAngleLOD( this->EnableViewAngleLOD );
  follower->SetViewAngleLODThreshold( this->ViewAngleLODThreshold );
200
201
202
203
204
205

  // Properties of the radial axes, with default color black
  this->RadialAxesProperty = vtkProperty::New();
  this->RadialAxesProperty->SetColor( 0., 0., 0. );

  // Create and set radial axes of type X
206
207
  this->RadialAxes = new vtkAxisActor*[VTK_MAXIMUM_NUMBER_OF_RADIAL_AXES];
  for ( int i = 0; i < VTK_MAXIMUM_NUMBER_OF_RADIAL_AXES; ++ i )
208
    {
209
    // Create axis of type X
210
    this->RadialAxes[i] = vtkAxisActor::New();
211
212
    vtkAxisActor* axis = this->RadialAxes[i];
    axis->SetAxisTypeToX();
213
214
    axis->SetAxisPositionToMinMax();
    axis->SetCalculateTitleOffset( 0 );
215
    axis->SetCalculateLabelOffset( 0 );
216

217
    // Set radial axis title follower
218
219
    axis->GetTitleActor()->SetAxis( axis );
    axis->GetTitleActor()->SetScreenOffset( .67 * offset );
220
    axis->GetTitleActor()->SetEnableDistanceLOD( this->EnableDistanceLOD );
221
    axis->GetTitleActor()->SetDistanceLODThreshold( this->DistanceLODThreshold );
222
223
    axis->GetTitleActor()->SetEnableViewAngleLOD( this->EnableViewAngleLOD );
    axis->GetTitleActor()->SetViewAngleLODThreshold( this->ViewAngleLODThreshold );
224
    } // for ( int i = 0; i < VTK_MAXIMUM_NUMBER_OF_RADIAL_AXES; ++ i )
225

226
  // Create and set polar arcs and ancillary objects, with default color white
227
228
229
230
231
  this->PolarArcs = vtkPolyData::New();
  this->PolarArcsMapper = vtkPolyDataMapper::New();
  this->PolarArcsMapper->SetInput( this->PolarArcs );
  this->PolarArcsActor = vtkActor::New();
  this->PolarArcsActor->SetMapper( this->PolarArcsMapper );
232
  this->PolarArcsActor->GetProperty()->SetColor( 1., 1., 1. );
233

234
  // Default title for polar axis (sometimes also called "Radius")
235
236
  this->PolarAxisTitle = new char[16];
  sprintf(this->PolarAxisTitle, "%s", "Radial Distance");
237
238
  this->PolarLabelFormat = new char[8];
  sprintf( this->PolarLabelFormat, "%s", "%-#6.3g" );
239

240
241
242
243
244
245
246
247
248
249
250
251
  // By default all polar axis features are visible
  this->PolarAxisVisibility = 1;
  this->PolarTitleVisibility = 1;
  this->PolarLabelVisibility = 1;
  this->PolarTickVisibility = 1;

  // By default all radial axes features are visible
  this->RadialAxesVisibility = 1;
  this->RadialTitleVisibility = 1;

  // By default polar arcs are visible
  this->PolarArcsVisibility = 1;
252

253
254
255
256
257
258
  // Default title scale
  this->TitleScale = -1.;

  // Default label scale
  this->LabelScale = -1.;

259
260
261
262
263
  this->RenderCount = 0;

  this->RenderSomething = 0;
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
264
//-----------------------------------------------------------------------------
265
266
267
268
vtkPolarAxesActor::~vtkPolarAxesActor()
{
  this->SetCamera( NULL );

269
270
271
272
273
  if ( this->PolarAxisProperty )
    {
    this->PolarAxisProperty->Delete();
    }

Philippe Pébay's avatar
Philippe Pébay committed
274
  if ( this->RadialAxesProperty )
275
276
277
278
    {
    this->RadialAxesProperty->Delete();
    }

279
  if ( this->PolarLabelFormat )
280
    {
281
282
    delete [] this->PolarLabelFormat;
    this->PolarLabelFormat = NULL;
283
    }
Philippe Pébay's avatar
Philippe Pébay committed
284

Philippe Pébay's avatar
Philippe Pébay committed
285
  if ( this->PolarAxisTitle )
286
287
288
289
290
    {
    delete [] this->PolarAxisTitle;
    this->PolarAxisTitle = NULL;
    }

Philippe Pébay's avatar
Philippe Pébay committed
291
292
293
294
295
296
297
298
299
300
301
302
  if ( this->PolarAxisTitleTextProperty )
    {
    this->PolarAxisTitleTextProperty->Delete();
    this->PolarAxisTitleTextProperty = NULL;
    }

  if ( this->PolarAxisLabelTextProperty )
    {
    this->PolarAxisLabelTextProperty->Delete();
    this->PolarAxisLabelTextProperty = NULL;
    }

303
304
305
306
307
308
  if ( this->PolarAxis )
    {
    this->PolarAxis->Delete();
    this->PolarAxis = NULL;
    }

Philippe Pébay's avatar
Philippe Pébay committed
309
310
  if ( this->RadialAxes )
    {
311
    for ( int i = 0; i < VTK_MAXIMUM_NUMBER_OF_RADIAL_AXES; ++ i )
Philippe Pébay's avatar
Philippe Pébay committed
312
313
314
315
316
317
318
319
320
321
      {
      if ( this->RadialAxes[i] )
        {
        this->RadialAxes[i]->Delete();
        this->RadialAxes[i] = NULL;
        }
      }
    delete [] this->RadialAxes;
    this->RadialAxes = NULL;
    }
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338

  if (this->PolarArcs)
    {
    this->PolarArcs->Delete();
    this->PolarArcs = NULL;
    }
  if (this->PolarArcsMapper)
    {
    this->PolarArcsMapper->Delete();
    this->PolarArcsMapper = NULL;
    }
  if (this->PolarArcsActor)
    {
    this->PolarArcsActor->Delete();
    this->PolarArcsActor = NULL;
    }

339
340
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
341
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
342
int vtkPolarAxesActor::RenderOpaqueGeometry( vtkViewport *viewport )
343
344
345
{
  // Initialization
  static bool initialRender = true;
346
  if ( !this->Camera )
347
348
349
350
351
352
353
354
    {
    vtkErrorMacro( <<"No camera!" );
    this->RenderSomething = 0;
    return 0;
    }

  this->BuildAxes( viewport );

355
  if ( initialRender )
356
    {
357
358
    this->PolarAxis->BuildAxis( viewport, true );

359
360
    for ( int i = 0; i < this->NumberOfRadialAxes; ++ i )
      {
Philippe Pébay's avatar
Philippe Pébay committed
361
      this->RadialAxes[i]->BuildAxis( viewport, true );
362
363
364
365
366
      }
    }
  initialRender = false;

  int renderedSomething = 0;
367
368
369
370
371
372
373
374

  // Render the polar axis
  if ( this->PolarAxisVisibility )
    {
    renderedSomething += this->PolarAxis->RenderOpaqueGeometry( viewport );
    }

  // Render the radial axes
375
376
377
378
  if ( this->RadialAxesVisibility )
    {
    for ( int i = 0; i < this->NumberOfRadialAxes; ++ i )
      {
379
      renderedSomething += this->RadialAxes[i]->RenderOpaqueGeometry( viewport );
380
381
382
      }
    }

383
384
385
386
387
388
  // Render the polar arcs
  if ( this->PolarArcsVisibility )
    {
    renderedSomething += this->PolarArcsActor->RenderOpaqueGeometry(viewport);
    }

389
390
391
  return renderedSomething;
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
392
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
393
void vtkPolarAxesActor::SetScreenSize( double screenSize )
394
395
{
  this->ScreenSize = screenSize;
396
397
  // Considering pivot point at center of the geometry,
  // hence ( this->ScreenSize * 0.5 ).
Philippe Pébay's avatar
Philippe Pébay committed
398
  this->LabelScreenOffset = 15.0 + this->ScreenSize * 0.5;
399

400
401
402
  vtkAxisFollower** labelActors = this->PolarAxis->GetLabelActors();
  int numberOfLabels = this->PolarAxis->GetNumberOfLabelsBuilt();
  for( int i = 0; i < numberOfLabels; ++ i )
403
    {
404
    labelActors[i]->SetScreenOffset( this->LabelScreenOffset );
405
406
407
408
409
    }

  this->Modified();
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
410
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
411
void vtkPolarAxesActor::ReleaseGraphicsResources( vtkWindow *win )
412
{
413
  this->PolarAxis->ReleaseGraphicsResources(win);
414
  for ( int i = 0; i < this->NumberOfRadialAxes;  ++ i )
415
    {
Philippe Pébay's avatar
Philippe Pébay committed
416
    this->RadialAxes[i]->ReleaseGraphicsResources( win );
417
    }
418
  this->PolarArcsActor->ReleaseGraphicsResources( win );
419
420
}

421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
//-----------------------------------------------------------------------------
void vtkPolarAxesActor::CalculateBounds()
{
  // Fetch angles, at this point it is already known that angular sector <= 360.
  double minAngle = this->MinimumAngle;
  double maxAngle = this->MaximumAngle;

  // Ensure that angles are not both < -180 nor both > 180 degrees
  if ( maxAngle < -180. )
    {
    // Increment angles modulo 360 degrees
    minAngle += 360.;
    maxAngle += 360.;
    }
  else if ( minAngle > 180. )
    {
    // Decrement angles modulo 360 degrees
    minAngle -= 360.;
    maxAngle -= 360.;
    }

  // Prepare trigonometric quantities
  double thetaMin = vtkMath::RadiansFromDegrees( minAngle );
  double cosThetaMin = cos( thetaMin );
  double sinThetaMin = sin( thetaMin );
  double thetaMax = vtkMath::RadiansFromDegrees( maxAngle );
  double cosThetaMax = cos( thetaMax );
  double sinThetaMax = sin( thetaMax );

  // Calculate extremal cosines across angular sector
  double minCos;
  double maxCos;
  if ( minAngle * maxAngle < 0. )
    {
    // Angular sector contains null angle
    maxCos = 1.;
    if ( minAngle < 180. && maxAngle > 180. )
      {
      // Angular sector also contains flat angle
      minCos = -1.;
      }
    else
      {
      // Angular sector does not contain flat angle
      minCos = cosThetaMin < cosThetaMax ? cosThetaMin : cosThetaMax;
      }

    }
  else if ( minAngle < 180. && maxAngle > 180. )
    {
    // Angular sector does not contain flat angle (and not null angle)
    minCos = -1.;
    maxCos = cosThetaMax > cosThetaMin ? cosThetaMax : cosThetaMin;
    }
  else
    {
    // Angular sector does not contain flat nor null angle
    minCos = cosThetaMin < cosThetaMax ? cosThetaMin : cosThetaMax;
    maxCos = cosThetaMax > cosThetaMin ? cosThetaMax : cosThetaMin;
    }

  // Calculate extremal sines across angular sector
  double minSin;
  double maxSin;
  if ( minAngle < -90. && maxAngle > -90. )
    {
    // Angular sector contains negative right angle
    minSin = -1.;
    if ( minAngle < 90. && maxAngle > 90. )
      {
      // Angular sector also contains positive right angle
      maxSin = 1.;
      }
    else
      {
      // Angular sector contain does not contain positive right angle
      maxSin = sinThetaMax > sinThetaMin ? sinThetaMax : sinThetaMin;
      }
    }
  else if ( minAngle < 90. && maxAngle > 90. )
    {
    // Angular sector contains positive right angle (and not negative one)
    minSin = sinThetaMin < sinThetaMax ? sinThetaMin : sinThetaMax;
    maxSin = 1.;
    }
  else
    {
    // Angular sector contain does not contain either right angle
    minSin = sinThetaMin < sinThetaMax ? sinThetaMin : sinThetaMax;
    maxSin = sinThetaMax > sinThetaMin ? sinThetaMax : sinThetaMin;
    }

  // Now calculate bounds
  // xmin
  this->Bounds[0] = this->Pole[0] + this->MaximumRadius * minCos;
  // xmax
  this->Bounds[1] = this->Pole[0] + this->MaximumRadius * maxCos;
  // ymin
  this->Bounds[2] = this->Pole[1] + this->MaximumRadius * minSin;
  // ymax
  this->Bounds[3] = this->Pole[1] + this->MaximumRadius * maxSin;
  // zmin
  this->Bounds[4] = this->Pole[2];
  // zmax
  this->Bounds[5] = this->Pole[2];
526
527
528

  // Update modification time of bounds
  this->BoundsMTime.Modified();
529
530
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
531
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
532
void vtkPolarAxesActor::GetBounds( double bounds[6])
533
{
Philippe Pébay's avatar
Philippe Pébay committed
534
  for ( int i=0; i< 6; i++)
535
536
537
538
539
    {
    bounds[i] = this->Bounds[i];
    }
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
540
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
541
void vtkPolarAxesActor::GetBounds( double& xmin, double& xmax,
542
543
                                   double& ymin, double& ymax,
                                   double& zmin, double& zmax )
544
545
546
547
548
549
550
551
552
{
  xmin = this->Bounds[0];
  xmax = this->Bounds[1];
  ymin = this->Bounds[2];
  ymax = this->Bounds[3];
  zmin = this->Bounds[4];
  zmax = this->Bounds[5];
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
553
//-----------------------------------------------------------------------------
554
555
556
557
558
double *vtkPolarAxesActor::GetBounds()
{
  return this->Bounds;
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
559
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
560
void vtkPolarAxesActor::BuildAxes( vtkViewport *viewport )
561
{
562
  if ( ( this->GetMTime() < this->BuildTime.GetMTime() ) )
563
    {
Philippe Pébay's avatar
Philippe Pébay committed
564
    this->AutoScale( viewport );
565
566
567
    return;
    }

568
  if ( this->MaximumAngle < this->MinimumAngle )
569
570
571
572
573
    {
    // Incorrect angle input
    vtkWarningMacro( << "Cannot draw radial axes: "
                     << " minimum angle = "
                     << this->MinimumAngle
574
575
576
577
578
579
                     << " > maximum angle = "
                     << this->MaximumAngle
                     << ".");
    return;
    }
  
580
  if ( this->MaximumAngle - this->MinimumAngle > 360. )
581
582
583
584
585
586
    {
    // Incorrect angle input
    vtkWarningMacro( << "Cannot draw radial axes: "
                     << " angular sector = "
                     << this->MaximumAngle - this->MinimumAngle
                     << " > 360 deg." );
587
588
589
    return;
    }
  
590
  // Determine the bounds
591
592
  this->CalculateBounds();
  
593
594
  // Set polar axis endpoints
  vtkAxisActor* axis = this->PolarAxis;
595
596
597
  double ox = this->Pole[0] + this->MaximumRadius;
  axis->GetPoint1Coordinate()->SetValue( this->Pole[0], this->Pole[1], this->Pole[2] );
  axis->GetPoint2Coordinate()->SetValue( ox, this->Pole[1], this->Pole[2] );
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612

  // Set common axis attributes
  this->SetCommonAxisAttributes( axis );

  // Set polar axis lines
  axis->SetAxisVisibility( this->PolarAxisVisibility );
  axis->SetAxisLinesProperty( this->PolarAxisProperty );

  // Set polar axis title
  axis->SetTitleVisibility( this->PolarTitleVisibility );
  axis->SetTitle( this->PolarAxisTitle );
  axis->SetTitleTextProperty( this->PolarAxisTitleTextProperty );

  // Set polar axis ticks (major only)
  axis->SetTickVisibility( this->PolarTickVisibility );
613
  axis->SetTickLocation( VTK_TICKS_BOTH );
614
615
616
617
618
619
  axis->SetMajorTickSize( .02 * this->MaximumRadius );
  
  // Set polar axis labels
  axis->SetLabelVisibility( this->PolarLabelVisibility );
  axis->SetLabelTextProperty( this->PolarAxisLabelTextProperty );

620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
  // Build radial axes
  this->BuildRadialAxes();

  // Build polar axis ticks
  this->BuildPolarAxisTicks( this->Pole[0] );

  // Build polar axis labels
  this->BuildPolarAxisLabelsArcs();

  // Scale appropriately
  this->AutoScale( viewport );

  this->RenderSomething = 1;
  this->BuildTime.Modified();
}

//-----------------------------------------------------------------------------
void vtkPolarAxesActor::SetCommonAxisAttributes( vtkAxisActor* axis )
{
  vtkProperty *prop = this->GetProperty();
  prop->SetAmbient( 1.0 );
  prop->SetDiffuse( 0.0 );
  axis->SetProperty( prop );

  // Common space and range attributes
  axis->SetCamera( this->Camera );
  axis->SetBounds( this->Bounds );
  axis->SetRange( 0., this->MaximumRadius );

  // No minor ticks for any kind of axes
  axis->SetMinorTicksVisible( 0 );
}

//-----------------------------------------------------------------------------
inline double vtkPolarAxesActor::FFix( double value )
{
  int ivalue = static_cast<int>( value );
  return ivalue;
}

//-----------------------------------------------------------------------------
inline double vtkPolarAxesActor::FSign( double value, double sign )
{
  value = fabs( value );
  if ( sign < 0.)
    {
    value *= -1.;
    }
  return value;
}

//-----------------------------------------------------------------------------
void vtkPolarAxesActor::BuildRadialAxes()
{
674
675
676
677
678
  // Create requested number of radial axes
  double dAlpha = 
    ( this->MaximumAngle  - this->MinimumAngle ) / ( this->NumberOfRadialAxes - 1. );
  double alpha = this->MinimumAngle;
  for ( int i = 0; i < this->NumberOfRadialAxes;  ++ i, alpha += dAlpha )
679
    {
680
681
    // Calculate endpoint coordinates
    double alphaRad = vtkMath::RadiansFromDegrees( alpha );
682
683
    double x = this->Pole[0] + this->MaximumRadius * cos( alphaRad );
    double y = this->Pole[1] + this->MaximumRadius * sin( alphaRad );
684
685

    // Set radial axis endpoints
686
    vtkAxisActor* axis = this->RadialAxes[i];
687
688
    axis->GetPoint1Coordinate()->SetValue( this->Pole[0], this->Pole[1], this->Pole[2] );
    axis->GetPoint2Coordinate()->SetValue( x, y, this->Pole[2] );
Philippe Pébay's avatar
Philippe Pébay committed
689

690
691
    // Set common axis attributes
    this->SetCommonAxisAttributes( axis );
692

693
694
695
    // Set radial axis lines
    axis->SetAxisVisibility( this->RadialAxesVisibility );
    axis->SetAxisLinesProperty( this->RadialAxesProperty );
696

697
    // Set radial axis title with polar angle as title for non-polar axes
698
699
700
701
    if ( this->PolarAxisVisibility && fabs( alpha ) < 2. )
      { 
      // Prevent conflict between radial and polar axes titles
      axis->SetTitleVisibility( false );
702
703
704
705
706
707

      if ( fabs( alpha ) < this->SmallestVisiblePolarAngle )
        { 
        // Do not show radial axes too close to polar axis
        axis->SetAxisVisibility( false );
        }
708
709
710
711
712
713
714
715
716
717
718
      }
    else
      {
      // Use polar angle as a title for the radial axis
      axis->SetTitleVisibility( this->RadialTitleVisibility );
      axis->GetTitleTextProperty()->SetColor( this->RadialAxesProperty->GetColor() );
      vtksys_ios::ostringstream title;
      title << alpha
            << ( this->RadialUnits ? " deg" : "" );
      axis->SetTitle( title.str().c_str() );
      }
719
720
721
722

    // No labels nor ticks for radial axes
    axis->SetLabelVisibility( 0 );
    axis->SetTickVisibility( 0 );
723
    }
724
725
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
726
//-----------------------------------------------------------------------------
727
void vtkPolarAxesActor::BuildPolarAxisTicks( double x0 )
728
{
729
  double delta;
730

731
732
733
  if ( this->AutoSubdividePolarAxis
       || this->NumberOfPolarAxisTicks < 0
       || this->NumberOfPolarAxisTicks > VTK_MAXIMUM_NUMBER_OF_POLAR_AXIS_TICKS )
734
    {
735
736
    // Programatically figure the number of divisions of the polar axis
    double pow10 = log10( this->MaximumRadius );
737

738
739
740
741
742
743
    // Build in numerical tolerance
    if ( pow10 != 0.)
      {
      double eps = 10.0e-10;
      pow10 = this->FSign( ( fabs( pow10 ) + eps ), pow10 );
      }
744

745
746
747
748
749
    // FFix will move in the wrong direction if pow10 is negative.
    if ( pow10 < 0.)
      {
      pow10 = pow10 - 1.;
      }
750

751
752
753
754
755
756
    // Find the number of integral points in the interval.
    delta = pow( 10., this->FFix( pow10 ) );
    double fnt = this->MaximumRadius / delta;
    fnt  = this->FFix( fnt );
    int numTicks = fnt <= 0.5 ? 
      static_cast<int>( this->FFix( fnt ) ) : static_cast<int>( this->FFix( fnt ) + 1 );
757

758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
    // If not enough tick points in this decade, scale down
    double div = 1.;
    if ( numTicks < 5 )
      {
      div = 2.;
      }
    if ( numTicks <= 2 )
      {
      div = 5.;
      }
    if ( div != 1.)
      {
      delta /= div;
      }

    // Finally calculate number of tick points
    this->NumberOfPolarAxisTicks = 0;
    while ( delta * this->NumberOfPolarAxisTicks <= this->MaximumRadius )
      {
      ++ this->NumberOfPolarAxisTicks;
      }
    }
  else // if ( this->AutoSubdividePolarAxis || this->NumberOfPolarAxisTicks ... )
781
    {
782
783
    // Use pre-set number of arcs when it is valid and no auto-subdivision was requested
    delta =  this->MaximumRadius / ( this->NumberOfPolarAxisTicks - 1 );
784
    }
785
  // Set major start and delta corresponding to range and coordinates
786
787
788
  this->PolarAxis->SetMajorRangeStart( 0. );
  this->PolarAxis->SetDeltaRangeMajor( delta );
  this->PolarAxis->SetMajorStart( VTK_AXIS_TYPE_X, x0 );
789

790
  // Build in numerical robustness to avoid truncation errors at endpoint
791
  delta *= VTK_POLAR_AXES_ACTOR_RTOL;
792
  this->PolarAxis->SetDeltaMajor( VTK_AXIS_TYPE_X, delta );
793
794
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
795
//-----------------------------------------------------------------------------
796
void vtkPolarAxesActor::BuildPolarAxisLabelsArcs()
797
{
798
  // Prepare storage for polar axis labels
799
  vtkStringArray *labels = vtkStringArray::New();
800
  labels->SetNumberOfValues( this->NumberOfPolarAxisTicks );
801

802
  // Prepare trigonometric quantities
803
804
805
806
807
808
809
  double thetaMin = vtkMath::RadiansFromDegrees( this->MinimumAngle );
  double cosThetaMin = cos( thetaMin );
  double sinThetaMin = sin( thetaMin );
  double thetaMax = vtkMath::RadiansFromDegrees( this->MaximumAngle );
  double cosThetaMax = cos( thetaMax );
  double sinThetaMax = sin( thetaMax );
  double angularSector = this->MaximumAngle - this->MinimumAngle;
Aashish Chaudhary's avatar
Aashish Chaudhary committed
810
  vtkIdType arcResolution
811
    = static_cast<vtkIdType>( angularSector * VTK_POLAR_ARC_RESOLUTION_PER_DEG );
812

813
  // Arc points
814
  vtkPoints* polarArcsPoints = vtkPoints::New();
815
816
  this->PolarArcs->SetPoints( polarArcsPoints );
  polarArcsPoints->Delete();
817

818
  // Arc lines
819
  vtkCellArray* polarArcsLines = vtkCellArray::New();
820
821
822
  this->PolarArcs->SetLines( polarArcsLines );
  polarArcsLines->Delete();

823
  // Retreave label features
824
  vtkAxisActor* axis = this->PolarAxis;
825
826
827
828
  double delta = axis->GetDeltaMajor( VTK_AXIS_TYPE_X );
  double value = axis->GetMajorRangeStart();

  // Now create labels and polar arcs
829
  const char *format = this->PolarLabelFormat;
830
  char label[64];
831
  vtkIdType pointIdOffset = 0;
832
  for ( int  i = 0; i < this->NumberOfPolarAxisTicks; ++ i )
833
    {
834
    // Store label
835
    sprintf( label, format, value );
836
    labels->SetValue( i, label );
837

838
    if ( value  > 0. )
839
      {
840
      // Build corresponding polar arc for non-zero values
841
842
843
844
      double x1 = value * cosThetaMin;
      double y1 = value * sinThetaMin;
      double x2 = value * cosThetaMax;
      double y2 = value * sinThetaMax;
845
      vtkArcSource* arc = vtkArcSource::New();
846
847
848
      arc->SetCenter( this->Pole );
      arc->SetPoint1( this->Pole[0] + x1, this->Pole[1] + y1, this->Pole[2] );
      arc->SetPoint2( this->Pole[0] + x2, this->Pole[1] + y2, this->Pole[2] );
849
      arc->SetResolution( arcResolution );
850
      arc->SetNegative( angularSector > 180. );
851
      arc->Update();
Aashish Chaudhary's avatar
Aashish Chaudhary committed
852

853
854
855
856
857
858
859
860
861
862
      // Append new polar arc to existing ones
      vtkPoints* arcPoints = arc->GetOutput()->GetPoints();
      vtkIdType nPoints = arcResolution + 1;
      vtkIdType* arcPointIds = new vtkIdType[nPoints];
      for ( vtkIdType j = 0; j < nPoints; ++ j )
        {
        polarArcsPoints->InsertNextPoint( arcPoints->GetPoint( j ) );
        arcPointIds[j] = pointIdOffset + j;
        }
      polarArcsLines->InsertNextCell( nPoints, arcPointIds );
Aashish Chaudhary's avatar
Aashish Chaudhary committed
863

864
865
866
      // Clean up
      arc->Delete();
      delete [] arcPointIds;
Aashish Chaudhary's avatar
Aashish Chaudhary committed
867

868
869
      // Update polyline cell offset
      pointIdOffset += nPoints;
870
871
872
      }

    // Move to next value
873
    value += delta;
874
    }
875
876

  // Store labels
877
  this->PolarAxis->SetLabels( labels );
878
879

  // Clean up
880
  labels->Delete();
881
882
883

  // Update axis label followers
  vtkAxisFollower** labelActors = axis->GetLabelActors();
884
  for( int i = 0; i < this->NumberOfPolarAxisTicks; ++ i )
885
886
887
    {
    labelActors[i]->SetAxis( axis );
    labelActors[i]->SetScreenOffset( this->LabelScreenOffset );
888
    labelActors[i]->SetEnableDistanceLOD( this->EnableDistanceLOD );
889
890
891
    labelActors[i]->SetDistanceLODThreshold( this->DistanceLODThreshold );
    labelActors[i]->SetEnableViewAngleLOD( this->EnableViewAngleLOD );
    labelActors[i]->SetViewAngleLODThreshold( this->ViewAngleLODThreshold );
892
    }
893
894
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
895
//-----------------------------------------------------------------------------
896
897
898
void vtkPolarAxesActor::AutoScale( vtkViewport *viewport )
{

899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
  // Scale polar axis title
  vtkAxisActor* axis = this->PolarAxis;
  double newTitleScale
    = vtkAxisFollower::AutoScale( viewport, 
                                  this->Camera,
                                  this->ScreenSize, 
                                  axis->GetTitleActor()->GetPosition() );
  axis->SetTitleScale( newTitleScale );

  // Scale polar axis labels
  vtkAxisFollower** labelActors = axis->GetLabelActors();
  for( int i = 0; i < axis->GetNumberOfLabelsBuilt(); ++ i )
    {
    double newLabelScale 
      = vtkAxisFollower::AutoScale( viewport,
                                    this->Camera, 
                                    this->ScreenSize, 
                                    labelActors[i]->GetPosition() );
    labelActors[i]->SetScale( newLabelScale );
    }
919
920

  // Loop over radial axes
921
922
  for ( int i = 0; i < this->NumberOfRadialAxes; ++ i )
    {
923
    axis = this->RadialAxes[i];
924
    // Scale title
925
926
927
928
929
930
    newTitleScale 
      = vtkAxisFollower::AutoScale( viewport, 
                                    this->Camera,
                                    this->ScreenSize,
                                    axis->GetTitleActor()->GetPosition() );
    axis->SetTitleScale( newTitleScale );
931
    }
932
933
}

934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
//-----------------------------------------------------------------------------
void vtkPolarAxesActor::SetPole( double p[3] )
{
  this->Pole[0] = p[0];
  this->Pole[1] = p[1];
  this->Pole[2] = p[2];

  // Update bounds
  this->CalculateBounds();
  this->Modified();
}

//-----------------------------------------------------------------------------
void vtkPolarAxesActor::SetPole( double x, double y, double z )
{
  this->Pole[0] = x;
  this->Pole[1] = y;
  this->Pole[2] = z;

  // Update bounds
  this->CalculateBounds();
  this->Modified();
}

958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
//-----------------------------------------------------------------------------
void vtkPolarAxesActor::SetMaximumRadius( double r )
{
  this->MaximumRadius = r > 0. ? r : 0.;

  // Update bounds
  this->CalculateBounds();
  this->Modified();
}

//-----------------------------------------------------------------------------
void vtkPolarAxesActor::SetMinimumAngle( double a )
{
  if ( a > 360. )
    {
    this->MinimumAngle = 360.;
    }
  else if ( a < -360. )
    {
    this->MinimumAngle = -360.;
    }
  else
    {
    this->MinimumAngle = a;
    }

  // Update bounds
  this->CalculateBounds();
  this->Modified();
}

//-----------------------------------------------------------------------------
void vtkPolarAxesActor::SetMaximumAngle( double a )
{
  if ( a > 360. )
    {
    this->MaximumAngle = 360.;
    }
  else if ( a < -360. )
    {
    this->MaximumAngle = -360.;
    }
  else
    {
    this->MaximumAngle = a;
    }

  // Update bounds
  this->CalculateBounds();
  this->Modified();
}

1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
//-----------------------------------------------------------------------------
void vtkPolarAxesActor::SetPolarAxisProperty( vtkProperty *prop )
{
  this->PolarAxisProperty->DeepCopy( prop );
  this->Modified();
}

//-----------------------------------------------------------------------------
vtkProperty* vtkPolarAxesActor::GetPolarAxisProperty()
{
  return this->PolarAxisProperty;
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
1023
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
1024
void vtkPolarAxesActor::SetRadialAxesProperty( vtkProperty *prop )
1025
{
Philippe Pébay's avatar
Philippe Pébay committed
1026
  this->RadialAxesProperty->DeepCopy( prop );
1027
1028
1029
  this->Modified();
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
1030
//-----------------------------------------------------------------------------
1031
1032
1033
1034
vtkProperty* vtkPolarAxesActor::GetRadialAxesProperty()
{
  return this->RadialAxesProperty;
}
1035

Aashish Chaudhary's avatar
Aashish Chaudhary committed
1036
//-----------------------------------------------------------------------------
1037
1038
1039
1040
1041
1042
void vtkPolarAxesActor::SetPolarArcsProperty( vtkProperty *prop )
{
  this->PolarArcsActor->SetProperty(prop);
  this->Modified();
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
1043
//-----------------------------------------------------------------------------
1044
1045
1046
1047
vtkProperty* vtkPolarAxesActor::GetPolarArcsProperty()
{
  return this->PolarArcsActor->GetProperty();
}