vtkPolarAxesActor.cxx 26.5 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

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

57
  os << indent << "Number Of Radial Axes" << this->NumberOfRadialAxes << endl;
58
59
60
  os << indent << "Number Of Polar Axis Ticks" << this->NumberOfPolarAxisTicks << endl;
  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
  os << indent << "Maximum Radius" << this->MaximumRadius << endl;
68
  os << indent << "Auto-Scale Radius" << this->AutoScaleRadius << endl;
69
  os << indent << "Minimum Angle" << this->MinimumAngle << endl;
70
  os << indent << "Maximum Angle" << this->MaximumAngle << endl;
Philippe Pébay's avatar
Philippe Pébay committed
71
72
  os << indent << "Radial Units (degrees): "
     << ( this->RadialUnits ? "On\n" : "Off\n" ) << endl;
73

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

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

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

Philippe Pébay's avatar
Philippe Pébay committed
92
  os << indent << "Polar Axis Title: " << this->PolarAxisTitle << "\n";
93
  os << indent << "Polar Label Format: " << this->PolarLabelFormat << "\n";
Philippe Pébay's avatar
Philippe Pébay committed
94
95
  os << indent << "PolarAxisLabelTextProperty: " << this->PolarAxisLabelTextProperty << endl;
  os << indent << "PolarAxisTitleTextProperty: " << this->PolarAxisTitleTextProperty << endl;
96
97
98
99
100
101
102
103
  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;
104
105

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

110

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

Aashish Chaudhary's avatar
Aashish Chaudhary committed
115
//-----------------------------------------------------------------------------
116
117
vtkPolarAxesActor::vtkPolarAxesActor() : vtkActor()
{
118
119
120
121
122
  // 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;

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

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

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

135
136
137
  // Default maximum polar radius
  this->MaximumRadius = VTK_DOUBLE_MAX;

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

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

144
145
146
147
  // Default maximum polar angle
  this->MaximumAngle = VTK_DEFAULT_MAXIMUM_POLAR_ANGLE;

  // By default show angle units (degrees)
148
  this->RadialUnits = true;
149
150
151

  this->Camera = NULL;

152
  // Default text screen size
153
154
  this->ScreenSize = 10.0;

155
156
  // 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
157
  this->LabelScreenOffset = 15.0 + this->ScreenSize * 0.5;
158

159
  // Text properties of polar axis title and labels, with default color white
160
161
162
  // 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
163
  this->PolarAxisTitleTextProperty = vtkTextProperty::New();
164
  this->PolarAxisTitleTextProperty->SetColor( 1., 1. ,1. );
Philippe Pébay's avatar
Philippe Pébay committed
165
166
  this->PolarAxisTitleTextProperty->SetFontFamilyToArial();
  this->PolarAxisLabelTextProperty = vtkTextProperty::New();
167
  this->PolarAxisLabelTextProperty->SetColor( 1., 1. ,1. );
Philippe Pébay's avatar
Philippe Pébay committed
168
169
  this->PolarAxisLabelTextProperty->SetFontFamilyToArial();

170
171
172
173
174
175
176
177
178
179
  // 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;

180
181
182
183
  // By default enable distance based LOD
  this->EnableDistanceLOD = 1;
  this->DistanceLODThreshold = .7;

184
185
186
187
  // By default enable view angle based LOD
  this->EnableViewAngleLOD = 1;
  this->ViewAngleLODThreshold = .3;

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

  // 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
202
203
  this->RadialAxes = new vtkAxisActor*[VTK_MAXIMUM_NUMBER_OF_RADIAL_AXES];
  for ( int i = 0; i < VTK_MAXIMUM_NUMBER_OF_RADIAL_AXES; ++ i )
204
    {
205
    // Create axis of type X
206
    this->RadialAxes[i] = vtkAxisActor::New();
207
208
    vtkAxisActor* axis = this->RadialAxes[i];
    axis->SetAxisTypeToX();
209
210
    axis->SetAxisPositionToMinMax();
    axis->SetCalculateTitleOffset( 0 );
211
    axis->SetCalculateLabelOffset( 0 );
212

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

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

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

236
237
238
239
240
241
242
243
244
245
246
247
  // 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;
248

249
250
251
252
253
254
  // Default title scale
  this->TitleScale = -1.;

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

255
256
257
258
259
  this->RenderCount = 0;

  this->RenderSomething = 0;
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
260
//-----------------------------------------------------------------------------
261
262
263
264
vtkPolarAxesActor::~vtkPolarAxesActor()
{
  this->SetCamera( NULL );

265
266
267
268
269
  if ( this->PolarAxisProperty )
    {
    this->PolarAxisProperty->Delete();
    }

Philippe Pébay's avatar
Philippe Pébay committed
270
  if ( this->RadialAxesProperty )
271
272
273
274
    {
    this->RadialAxesProperty->Delete();
    }

275
  if ( this->PolarLabelFormat )
276
    {
277
278
    delete [] this->PolarLabelFormat;
    this->PolarLabelFormat = NULL;
279
    }
Philippe Pébay's avatar
Philippe Pébay committed
280

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

Philippe Pébay's avatar
Philippe Pébay committed
287
288
289
290
291
292
293
294
295
296
297
298
  if ( this->PolarAxisTitleTextProperty )
    {
    this->PolarAxisTitleTextProperty->Delete();
    this->PolarAxisTitleTextProperty = NULL;
    }

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

299
300
301
302
303
304
  if ( this->PolarAxis )
    {
    this->PolarAxis->Delete();
    this->PolarAxis = NULL;
    }

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

  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;
    }

335
336
}

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

  this->BuildAxes( viewport );

351
  if ( initialRender )
352
    {
353
354
    this->PolarAxis->BuildAxis( viewport, true );

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

  int renderedSomething = 0;
363
364
365
366
367
368
369
370

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

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

379
380
381
382
383
384
  // Render the polar arcs
  if ( this->PolarArcsVisibility )
    {
    renderedSomething += this->PolarArcsActor->RenderOpaqueGeometry(viewport);
    }

385
386
387
  return renderedSomething;
}

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

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

  this->Modified();
}

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

416
417
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
418
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
419
void vtkPolarAxesActor::GetBounds( double bounds[6])
420
{
Philippe Pébay's avatar
Philippe Pébay committed
421
  for ( int i=0; i< 6; i++)
422
423
424
425
426
    {
    bounds[i] = this->Bounds[i];
    }
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
427
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
428
void vtkPolarAxesActor::GetBounds( double& xmin, double& xmax,
429
                                 double& ymin, double& ymax,
Philippe Pébay's avatar
Philippe Pébay committed
430
                                 double& zmin, double& zmax )
431
432
433
434
435
436
437
438
439
{
  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
440
//-----------------------------------------------------------------------------
441
442
443
444
445
double *vtkPolarAxesActor::GetBounds()
{
  return this->Bounds;
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
446
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
447
void vtkPolarAxesActor::BuildAxes( vtkViewport *viewport )
448
449
450
{
  double bounds[6];

Philippe Pébay's avatar
Philippe Pébay committed
451
  if ( ( this->GetMTime() < this->BuildTime.GetMTime() ))
452
    {
Philippe Pébay's avatar
Philippe Pébay committed
453
    this->AutoScale( viewport );
454
455
456
    return;
    }

457
  // Determine the bounds for possible use ( input, prop, or user-defined )
Philippe Pébay's avatar
Philippe Pébay committed
458
  this->GetBounds( bounds );
Aashish Chaudhary's avatar
Aashish Chaudhary committed
459

460
  // If pole coordinates are invalid, use bounds
461
  double O[3];
462
463
  for ( int i = 0; i < 3; ++ i )
    {
464
    O[i] = this->Pole[i] == VTK_DOUBLE_MAX ? bounds[i * 2] : this->Pole[i];
465
    }
Aashish Chaudhary's avatar
Aashish Chaudhary committed
466

467
468
469
  // If axial scale it out of proportions with object length scale, reset to ls
  double ls = fabs( bounds[1] -  bounds[0] ) + fabs( bounds[3] -  bounds[2] );
  if ( this->AutoScaleRadius
Aashish Chaudhary's avatar
Aashish Chaudhary committed
470
       || this->MaximumRadius < 1.e-6 * ls
471
472
473
474
       || this->MaximumRadius > 1.e6 * ls )
    {
    this->MaximumRadius = .5 * ls;
    }
475

476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
  // Set polar axis endpoints
  vtkAxisActor* axis = this->PolarAxis;
  double ox = O[0] + this->MaximumRadius;
  axis->GetPoint1Coordinate()->SetValue( O[0], O[1], O[2] );
  axis->GetPoint2Coordinate()->SetValue( ox, O[1], O[2] );

  // 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 );
496
  axis->SetTickLocation( VTK_TICKS_BOTH );
497
498
499
500
501
502
503
504
505
506
507
  axis->SetMajorTickSize( .02 * this->MaximumRadius );
  
  // Set polar axis labels
  axis->SetLabelVisibility( this->PolarLabelVisibility );
  axis->SetLabelTextProperty( this->PolarAxisLabelTextProperty );

  // 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 )
508
    {
509
510
511
512
513
514
515
    // Calculate endpoint coordinates
    double alphaRad = vtkMath::RadiansFromDegrees( alpha );
    double x = O[0] + this->MaximumRadius * cos( alphaRad );
    double y = O[1] + this->MaximumRadius * sin( alphaRad );

    // Set radial axis endpoints
    axis = this->RadialAxes[i];
516
517
    axis->GetPoint1Coordinate()->SetValue( O[0], O[1], O[2] );
    axis->GetPoint2Coordinate()->SetValue( x, y, O[2] );
Philippe Pébay's avatar
Philippe Pébay committed
518

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

522
523
524
    // Set radial axis lines
    axis->SetAxisVisibility( this->RadialAxesVisibility );
    axis->SetAxisLinesProperty( this->RadialAxesProperty );
525

526
    // Set radial axis title with polar angle as title for non-polar axes
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
    if ( this->PolarAxisVisibility && fabs( alpha ) < 2. )
      { 
      // Prevent conflict between radial and polar axes titles
      axis->SetTitleVisibility( false );
      }
    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() );
      }
542
543
544
545

    // No labels nor ticks for radial axes
    axis->SetLabelVisibility( 0 );
    axis->SetTickVisibility( 0 );
546
    }
Aashish Chaudhary's avatar
Aashish Chaudhary committed
547

548
549
  // Build polar axis ticks
  this->BuildPolarAxisTicks( O[0] );
550

551
552
  // Build polar axis labels
  this->BuildPolarAxisLabelsArcs( O );
553

554
  // Scale appropriately
555
556
557
558
559
560
  this->AutoScale( viewport );

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

Aashish Chaudhary's avatar
Aashish Chaudhary committed
561
//-----------------------------------------------------------------------------
562
void vtkPolarAxesActor::SetCommonAxisAttributes( vtkAxisActor* axis )
563
564
{
  vtkProperty *prop = this->GetProperty();
Philippe Pébay's avatar
Philippe Pébay committed
565
566
  prop->SetAmbient( 1.0 );
  prop->SetDiffuse( 0.0 );
567
568
  axis->SetProperty( prop );

569
  // Common space and range attributes
570
571
572
573
574
575
  axis->SetCamera( this->Camera );
  axis->SetBounds( this->Bounds );
  axis->SetRange( 0., this->MaximumRadius );

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

Aashish Chaudhary's avatar
Aashish Chaudhary committed
578
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
579
inline double vtkPolarAxesActor::FFix( double value )
580
{
Philippe Pébay's avatar
Philippe Pébay committed
581
  int ivalue = static_cast<int>( value );
582
583
584
  return ivalue;
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
585
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
586
inline double vtkPolarAxesActor::FSign( double value, double sign )
587
{
Philippe Pébay's avatar
Philippe Pébay committed
588
589
  value = fabs( value );
  if ( sign < 0.)
590
591
592
593
594
595
    {
    value *= -1.;
    }
  return value;
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
596
//-----------------------------------------------------------------------------
597
void vtkPolarAxesActor::BuildPolarAxisTicks( double x0 )
598
{
599
  double delta;
600

601
602
603
  if ( this->AutoSubdividePolarAxis
       || this->NumberOfPolarAxisTicks < 0
       || this->NumberOfPolarAxisTicks > VTK_MAXIMUM_NUMBER_OF_POLAR_AXIS_TICKS )
604
    {
605
606
    // Programatically figure the number of divisions of the polar axis
    double pow10 = log10( this->MaximumRadius );
607

608
609
610
611
612
613
    // Build in numerical tolerance
    if ( pow10 != 0.)
      {
      double eps = 10.0e-10;
      pow10 = this->FSign( ( fabs( pow10 ) + eps ), pow10 );
      }
614

615
616
617
618
619
    // FFix will move in the wrong direction if pow10 is negative.
    if ( pow10 < 0.)
      {
      pow10 = pow10 - 1.;
      }
620

621
622
623
624
625
626
    // 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 );
627

628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
    // 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 ... )
651
    {
652
653
    // Use pre-set number of arcs when it is valid and no auto-subdivision was requested
    delta =  this->MaximumRadius / ( this->NumberOfPolarAxisTicks - 1 );
654
    }
655
  // Set major start and delta corresponding to range and coordinates
656
657
658
  this->PolarAxis->SetMajorRangeStart( 0. );
  this->PolarAxis->SetDeltaRangeMajor( delta );
  this->PolarAxis->SetMajorStart( VTK_AXIS_TYPE_X, x0 );
659

660
  // Build in numerical robustness to avoid truncation errors at endpoint
661
  delta *= VTK_POLAR_AXES_ACTOR_RTOL;
662
  this->PolarAxis->SetDeltaMajor( VTK_AXIS_TYPE_X, delta );
663
664
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
665
//-----------------------------------------------------------------------------
666
void vtkPolarAxesActor::BuildPolarAxisLabelsArcs( double* O )
667
{
668
  // Prepare storage for polar axis labels
669
  vtkStringArray *labels = vtkStringArray::New();
670
  labels->SetNumberOfValues( this->NumberOfPolarAxisTicks );
671

672
  // Prepare trigonometric quantities
673
674
675
676
677
678
679
  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
680
  vtkIdType arcResolution
681
    = static_cast<vtkIdType>( angularSector * VTK_POLAR_ARC_RESOLUTION_PER_DEG );
682

683
  // Arc points
684
  vtkPoints* polarArcsPoints = vtkPoints::New();
685
686
  this->PolarArcs->SetPoints( polarArcsPoints );
  polarArcsPoints->Delete();
687

688
  // Arc lines
689
  vtkCellArray* polarArcsLines = vtkCellArray::New();
690
691
692
  this->PolarArcs->SetLines( polarArcsLines );
  polarArcsLines->Delete();

693
  // Retreave label features
694
  vtkAxisActor* axis = this->PolarAxis;
695
696
697
698
  double delta = axis->GetDeltaMajor( VTK_AXIS_TYPE_X );
  double value = axis->GetMajorRangeStart();

  // Now create labels and polar arcs
699
  const char *format = this->PolarLabelFormat;
700
  char label[64];
701
  vtkIdType pointIdOffset = 0;
702
  for ( int  i = 0; i < this->NumberOfPolarAxisTicks; ++ i )
703
    {
704
    // Store label
705
    sprintf( label, format, value );
706
    labels->SetValue( i, label );
707

708
    if ( value  > 0. )
709
      {
710
      // Build corresponding polar arc for non-zero values
711
712
713
714
      double x1 = value * cosThetaMin;
      double y1 = value * sinThetaMin;
      double x2 = value * cosThetaMax;
      double y2 = value * sinThetaMax;
715
      vtkArcSource* arc = vtkArcSource::New();
716
      arc->SetCenter( O );
717
718
      arc->SetPoint1( O[0] + x1, O[1] + y1, O[2] );
      arc->SetPoint2( O[0] + x2, O[1] + y2, O[2] );
719
      arc->SetResolution( arcResolution );
720
      arc->SetNegative( angularSector > 180. );
721
      arc->Update();
Aashish Chaudhary's avatar
Aashish Chaudhary committed
722

723
724
725
726
727
728
729
730
731
732
      // 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
733

734
735
736
      // Clean up
      arc->Delete();
      delete [] arcPointIds;
Aashish Chaudhary's avatar
Aashish Chaudhary committed
737

738
739
      // Update polyline cell offset
      pointIdOffset += nPoints;
740
741
742
      }

    // Move to next value
743
    value += delta;
744
    }
745
746

  // Store labels
747
  this->PolarAxis->SetLabels( labels );
748
749

  // Clean up
750
  labels->Delete();
751
752
753

  // Update axis label followers
  vtkAxisFollower** labelActors = axis->GetLabelActors();
754
  for( int i = 0; i < this->NumberOfPolarAxisTicks; ++ i )
755
756
757
    {
    labelActors[i]->SetAxis( axis );
    labelActors[i]->SetScreenOffset( this->LabelScreenOffset );
758
    labelActors[i]->SetEnableDistanceLOD( this->EnableDistanceLOD );
759
760
761
    labelActors[i]->SetDistanceLODThreshold( this->DistanceLODThreshold );
    labelActors[i]->SetEnableViewAngleLOD( this->EnableViewAngleLOD );
    labelActors[i]->SetViewAngleLODThreshold( this->ViewAngleLODThreshold );
762
    }
763
764
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
765
//-----------------------------------------------------------------------------
766
767
768
void vtkPolarAxesActor::AutoScale( vtkViewport *viewport )
{

769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
  // 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 );
    }
789
790

  // Loop over radial axes
791
792
  for ( int i = 0; i < this->NumberOfRadialAxes; ++ i )
    {
793
    axis = this->RadialAxes[i];
794
    // Scale title
795
796
797
798
799
800
    newTitleScale 
      = vtkAxisFollower::AutoScale( viewport, 
                                    this->Camera,
                                    this->ScreenSize,
                                    axis->GetTitleActor()->GetPosition() );
    axis->SetTitleScale( newTitleScale );
801
    }
802
803
}

804
805
806
807
808
809
810
811
812
813
814
815
816
//-----------------------------------------------------------------------------
void vtkPolarAxesActor::SetPolarAxisProperty( vtkProperty *prop )
{
  this->PolarAxisProperty->DeepCopy( prop );
  this->Modified();
}

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

Aashish Chaudhary's avatar
Aashish Chaudhary committed
817
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
818
void vtkPolarAxesActor::SetRadialAxesProperty( vtkProperty *prop )
819
{
Philippe Pébay's avatar
Philippe Pébay committed
820
  this->RadialAxesProperty->DeepCopy( prop );
821
822
823
  this->Modified();
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
824
//-----------------------------------------------------------------------------
825
826
827
828
vtkProperty* vtkPolarAxesActor::GetRadialAxesProperty()
{
  return this->RadialAxesProperty;
}
829

Aashish Chaudhary's avatar
Aashish Chaudhary committed
830
//-----------------------------------------------------------------------------
831
832
833
834
835
836
void vtkPolarAxesActor::SetPolarArcsProperty( vtkProperty *prop )
{
  this->PolarArcsActor->SetProperty(prop);
  this->Modified();
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
837
//-----------------------------------------------------------------------------
838
839
840
841
vtkProperty* vtkPolarAxesActor::GetPolarArcsProperty()
{
  return this->PolarArcsActor->GetProperty();
}