vtkPolarAxesActor.cxx 25.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";

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

  os << indent << "Radial Axes Visibility: "
102
     << ( this->RadialAxesVisibility ? "On\n" : "Off\n" );
103
104
  os << indent << "Radial Title Visibility: "
     << ( this->RadialTitleVisibility ? "On" : "Off" ) << endl;
105

106

107
108
  os << indent << "Polar Arcs Visibility: "
     << ( this->PolarArcsVisibility ? "On" : "Off" ) << endl;
109
110
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
111
//-----------------------------------------------------------------------------
112
113
vtkPolarAxesActor::vtkPolarAxesActor() : vtkActor()
{
114
115
116
117
118
  // 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;

119
  // Default pole coordinates
120
121
122
  this->Pole[0] = VTK_DOUBLE_MAX;
  this->Pole[1] = VTK_DOUBLE_MAX;
  this->Pole[2] = VTK_DOUBLE_MAX;
123

124
  // Default number of radial axes
125
  this->NumberOfRadialAxes = VTK_MAXIMUM_NUMBER_OF_RADIAL_AXES;
126

127
128
129
130
  // Invalid default number of polar arcs, and auto-calculate by default
  this->NumberOfPolarAxisTicks = -1;
  this->AutoSubdividePolarAxis = true;

131
132
133
  // Default maximum polar radius
  this->MaximumRadius = VTK_DOUBLE_MAX;

134
135
136
  // Do not auto-scale radius by default
  this->AutoScaleRadius = false;

137
138
139
  // Default minimum polar angle
  this->MinimumAngle = 0.;

140
141
142
143
  // Default maximum polar angle
  this->MaximumAngle = VTK_DEFAULT_MAXIMUM_POLAR_ANGLE;

  // By default show angle units (degrees)
144
  this->RadialUnits = true;
145
146
147

  this->Camera = NULL;

148
  // Default text screen size
149
150
  this->ScreenSize = 10.0;

151
152
  // 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
153
  this->LabelScreenOffset = 15.0 + this->ScreenSize * 0.5;
154

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

166
167
168
169
170
171
172
173
174
175
  // 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;

176
177
178
179
  // By default enable distance based LOD
  this->EnableDistanceLOD = 1;
  this->DistanceLODThreshold = .7;

180
  // Set polar axis title follower (label followers not built yet)
181
182
183
  vtkAxisFollower* follower = this->PolarAxis->GetTitleActor();
  follower->SetAxis( this->PolarAxis );
  follower->SetScreenOffset( 2.0 * offset + 5 );
184
  follower->SetEnableDistanceLOD( this->EnableDistanceLOD );
185
  follower->SetDistanceLODThreshold( .8 * this->DistanceLODThreshold );
186
187
188
189
190
191

  // 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
192
193
  this->RadialAxes = new vtkAxisActor*[VTK_MAXIMUM_NUMBER_OF_RADIAL_AXES];
  for ( int i = 0; i < VTK_MAXIMUM_NUMBER_OF_RADIAL_AXES; ++ i )
194
    {
195
    // Create axis of type X
196
    this->RadialAxes[i] = vtkAxisActor::New();
197
198
    vtkAxisActor* axis = this->RadialAxes[i];
    axis->SetAxisTypeToX();
199
200
    axis->SetAxisPositionToMinMax();
    axis->SetCalculateTitleOffset( 0 );
201
    axis->SetCalculateLabelOffset( 0 );
202

203
    // Set radial axis title follower
204
205
    axis->GetTitleActor()->SetAxis( axis );
    axis->GetTitleActor()->SetScreenOffset( .67 * offset );
206
    axis->GetTitleActor()->SetEnableDistanceLOD( this->EnableDistanceLOD );
207
    axis->GetTitleActor()->SetDistanceLODThreshold( this->DistanceLODThreshold );
208
    } // for ( int i = 0; i < VTK_MAXIMUM_NUMBER_OF_RADIAL_AXES; ++ i )
209

210
  // Create and set polar arcs and ancillary objects, with default color white
211
212
213
214
215
  this->PolarArcs = vtkPolyData::New();
  this->PolarArcsMapper = vtkPolyDataMapper::New();
  this->PolarArcsMapper->SetInput( this->PolarArcs );
  this->PolarArcsActor = vtkActor::New();
  this->PolarArcsActor->SetMapper( this->PolarArcsMapper );
216
  this->PolarArcsActor->GetProperty()->SetColor( 1., 1., 1. );
217

218
  // Default title for polar axis (sometimes also called "Radius")
219
220
  this->PolarAxisTitle = new char[16];
  sprintf(this->PolarAxisTitle, "%s", "Radial Distance");
221
222
  this->PolarLabelFormat = new char[8];
  sprintf( this->PolarLabelFormat, "%s", "%-#6.3g" );
223

224
225
226
227
228
229
230
231
232
233
234
235
  // 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;
236

237
238
239
240
241
242
  // Default title scale
  this->TitleScale = -1.;

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

243
244
245
246
247
  this->RenderCount = 0;

  this->RenderSomething = 0;
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
248
//-----------------------------------------------------------------------------
249
250
251
252
vtkPolarAxesActor::~vtkPolarAxesActor()
{
  this->SetCamera( NULL );

253
254
255
256
257
  if ( this->PolarAxisProperty )
    {
    this->PolarAxisProperty->Delete();
    }

Philippe Pébay's avatar
Philippe Pébay committed
258
  if ( this->RadialAxesProperty )
259
260
261
262
    {
    this->RadialAxesProperty->Delete();
    }

263
  if ( this->PolarLabelFormat )
264
    {
265
266
    delete [] this->PolarLabelFormat;
    this->PolarLabelFormat = NULL;
267
    }
Philippe Pébay's avatar
Philippe Pébay committed
268

Philippe Pébay's avatar
Philippe Pébay committed
269
  if ( this->PolarAxisTitle )
270
271
272
273
274
    {
    delete [] this->PolarAxisTitle;
    this->PolarAxisTitle = NULL;
    }

Philippe Pébay's avatar
Philippe Pébay committed
275
276
277
278
279
280
281
282
283
284
285
286
  if ( this->PolarAxisTitleTextProperty )
    {
    this->PolarAxisTitleTextProperty->Delete();
    this->PolarAxisTitleTextProperty = NULL;
    }

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

287
288
289
290
291
292
  if ( this->PolarAxis )
    {
    this->PolarAxis->Delete();
    this->PolarAxis = NULL;
    }

Philippe Pébay's avatar
Philippe Pébay committed
293
294
  if ( this->RadialAxes )
    {
295
    for ( int i = 0; i < VTK_MAXIMUM_NUMBER_OF_RADIAL_AXES; ++ i )
Philippe Pébay's avatar
Philippe Pébay committed
296
297
298
299
300
301
302
303
304
305
      {
      if ( this->RadialAxes[i] )
        {
        this->RadialAxes[i]->Delete();
        this->RadialAxes[i] = NULL;
        }
      }
    delete [] this->RadialAxes;
    this->RadialAxes = NULL;
    }
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322

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

323
324
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
325
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
326
int vtkPolarAxesActor::RenderOpaqueGeometry( vtkViewport *viewport )
327
328
329
{
  // Initialization
  static bool initialRender = true;
330
  if ( !this->Camera )
331
332
333
334
335
336
337
338
    {
    vtkErrorMacro( <<"No camera!" );
    this->RenderSomething = 0;
    return 0;
    }

  this->BuildAxes( viewport );

339
  if ( initialRender )
340
    {
341
342
    this->PolarAxis->BuildAxis( viewport, true );

343
344
    for ( int i = 0; i < this->NumberOfRadialAxes; ++ i )
      {
Philippe Pébay's avatar
Philippe Pébay committed
345
      this->RadialAxes[i]->BuildAxis( viewport, true );
346
347
348
349
350
      }
    }
  initialRender = false;

  int renderedSomething = 0;
351
352
353
354
355
356
357
358

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

  // Render the radial axes
359
360
361
362
  if ( this->RadialAxesVisibility )
    {
    for ( int i = 0; i < this->NumberOfRadialAxes; ++ i )
      {
363
      renderedSomething += this->RadialAxes[i]->RenderOpaqueGeometry( viewport );
364
365
366
      }
    }

367
368
369
370
371
372
  // Render the polar arcs
  if ( this->PolarArcsVisibility )
    {
    renderedSomething += this->PolarArcsActor->RenderOpaqueGeometry(viewport);
    }

373
374
375
  return renderedSomething;
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
376
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
377
void vtkPolarAxesActor::SetScreenSize( double screenSize )
378
379
{
  this->ScreenSize = screenSize;
380
381
  // Considering pivot point at center of the geometry,
  // hence ( this->ScreenSize * 0.5 ).
Philippe Pébay's avatar
Philippe Pébay committed
382
  this->LabelScreenOffset = 15.0 + this->ScreenSize * 0.5;
383

384
385
386
  vtkAxisFollower** labelActors = this->PolarAxis->GetLabelActors();
  int numberOfLabels = this->PolarAxis->GetNumberOfLabelsBuilt();
  for( int i = 0; i < numberOfLabels; ++ i )
387
    {
388
    labelActors[i]->SetScreenOffset( this->LabelScreenOffset );
389
390
391
392
393
    }

  this->Modified();
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
394
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
395
void vtkPolarAxesActor::ReleaseGraphicsResources( vtkWindow *win )
396
{
397
  this->PolarAxis->ReleaseGraphicsResources(win);
398
399
  for ( int i = 0; i < this->NumberOfRadialAxes;  ++i )
    {
Philippe Pébay's avatar
Philippe Pébay committed
400
    this->RadialAxes[i]->ReleaseGraphicsResources( win );
401
    }
402
403
  this->PolarArcsActor->ReleaseGraphicsResources(win);

404
405
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
406
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
407
void vtkPolarAxesActor::GetBounds( double bounds[6])
408
{
Philippe Pébay's avatar
Philippe Pébay committed
409
  for ( int i=0; i< 6; i++)
410
411
412
413
414
    {
    bounds[i] = this->Bounds[i];
    }
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
415
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
416
void vtkPolarAxesActor::GetBounds( double& xmin, double& xmax,
417
                                 double& ymin, double& ymax,
Philippe Pébay's avatar
Philippe Pébay committed
418
                                 double& zmin, double& zmax )
419
420
421
422
423
424
425
426
427
{
  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
428
//-----------------------------------------------------------------------------
429
430
431
432
433
double *vtkPolarAxesActor::GetBounds()
{
  return this->Bounds;
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
434
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
435
void vtkPolarAxesActor::BuildAxes( vtkViewport *viewport )
436
437
438
{
  double bounds[6];

Philippe Pébay's avatar
Philippe Pébay committed
439
  if ( ( this->GetMTime() < this->BuildTime.GetMTime() ))
440
    {
Philippe Pébay's avatar
Philippe Pébay committed
441
    this->AutoScale( viewport );
442
443
444
    return;
    }

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

448
  // If pole coordinates are invalid, use bounds
449
  double O[3];
450
451
  for ( int i = 0; i < 3; ++ i )
    {
452
    O[i] = this->Pole[i] == VTK_DOUBLE_MAX ? bounds[i * 2] : this->Pole[i];
453
    }
Aashish Chaudhary's avatar
Aashish Chaudhary committed
454

455
456
457
  // 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
458
       || this->MaximumRadius < 1.e-6 * ls
459
460
461
462
       || this->MaximumRadius > 1.e6 * ls )
    {
    this->MaximumRadius = .5 * ls;
    }
463

464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
  // 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 );
484
  axis->SetTickLocation( VTK_TICKS_BOTH );
485
486
487
488
489
490
491
492
493
494
495
  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 )
496
    {
497
498
499
500
501
502
503
    // 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];
504
505
    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
506

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

510
511
512
    // Set radial axis lines
    axis->SetAxisVisibility( this->RadialAxesVisibility );
    axis->SetAxisLinesProperty( this->RadialAxesProperty );
513

514
515
516
517
518
519
520
521
522
523
524
    // Set radial axis title with polar angle as title for non-polar axes
    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() );

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

527
528
  // Build polar axis ticks
  this->BuildPolarAxisTicks( O[0] );
529

530
531
  // Build polar axis labels
  this->BuildPolarAxisLabelsArcs( O );
532

533
  // Scale appropriately
534
535
536
537
538
539
  this->AutoScale( viewport );

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

Aashish Chaudhary's avatar
Aashish Chaudhary committed
540
//-----------------------------------------------------------------------------
541
void vtkPolarAxesActor::SetCommonAxisAttributes( vtkAxisActor* axis )
542
543
{
  vtkProperty *prop = this->GetProperty();
Philippe Pébay's avatar
Philippe Pébay committed
544
545
  prop->SetAmbient( 1.0 );
  prop->SetDiffuse( 0.0 );
546
547
  axis->SetProperty( prop );

548
  // Common space and range attributes
549
550
551
552
553
554
  axis->SetCamera( this->Camera );
  axis->SetBounds( this->Bounds );
  axis->SetRange( 0., this->MaximumRadius );

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

Aashish Chaudhary's avatar
Aashish Chaudhary committed
557
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
558
inline double vtkPolarAxesActor::FFix( double value )
559
{
Philippe Pébay's avatar
Philippe Pébay committed
560
  int ivalue = static_cast<int>( value );
561
562
563
  return ivalue;
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
564
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
565
inline double vtkPolarAxesActor::FSign( double value, double sign )
566
{
Philippe Pébay's avatar
Philippe Pébay committed
567
568
  value = fabs( value );
  if ( sign < 0.)
569
570
571
572
573
574
    {
    value *= -1.;
    }
  return value;
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
575
//-----------------------------------------------------------------------------
576
void vtkPolarAxesActor::BuildPolarAxisTicks( double x0 )
577
{
578
  double delta;
579

580
581
582
  if ( this->AutoSubdividePolarAxis
       || this->NumberOfPolarAxisTicks < 0
       || this->NumberOfPolarAxisTicks > VTK_MAXIMUM_NUMBER_OF_POLAR_AXIS_TICKS )
583
    {
584
585
    // Programatically figure the number of divisions of the polar axis
    double pow10 = log10( this->MaximumRadius );
586

587
588
589
590
591
592
    // Build in numerical tolerance
    if ( pow10 != 0.)
      {
      double eps = 10.0e-10;
      pow10 = this->FSign( ( fabs( pow10 ) + eps ), pow10 );
      }
593

594
595
596
597
598
    // FFix will move in the wrong direction if pow10 is negative.
    if ( pow10 < 0.)
      {
      pow10 = pow10 - 1.;
      }
599

600
601
602
603
604
605
    // 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 );
606

607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
    // 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 ... )
630
    {
631
632
    // Use pre-set number of arcs when it is valid and no auto-subdivision was requested
    delta =  this->MaximumRadius / ( this->NumberOfPolarAxisTicks - 1 );
633
    }
634
  // Set major start and delta corresponding to range and coordinates
635
636
637
  this->PolarAxis->SetMajorRangeStart( 0. );
  this->PolarAxis->SetDeltaRangeMajor( delta );
  this->PolarAxis->SetMajorStart( VTK_AXIS_TYPE_X, x0 );
638

639
  // Build in numerical robustness to avoid truncation errors at endpoint
640
  delta *= VTK_POLAR_AXES_ACTOR_RTOL;
641
  this->PolarAxis->SetDeltaMajor( VTK_AXIS_TYPE_X, delta );
642
643
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
644
//-----------------------------------------------------------------------------
645
void vtkPolarAxesActor::BuildPolarAxisLabelsArcs( double* O )
646
{
647
  // Prepare storage for polar axis labels
648
  vtkStringArray *labels = vtkStringArray::New();
649
  labels->SetNumberOfValues( this->NumberOfPolarAxisTicks );
650

651
  // Prepare trigonometric quantities
652
653
654
655
656
657
658
  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
659
  vtkIdType arcResolution
660
    = static_cast<vtkIdType>( angularSector * VTK_POLAR_ARC_RESOLUTION_PER_DEG );
661

662
  // Arc points
663
  vtkPoints* polarArcsPoints = vtkPoints::New();
664
665
  this->PolarArcs->SetPoints( polarArcsPoints );
  polarArcsPoints->Delete();
666

667
  // Arc lines
668
  vtkCellArray* polarArcsLines = vtkCellArray::New();
669
670
671
  this->PolarArcs->SetLines( polarArcsLines );
  polarArcsLines->Delete();

672
  // Retreave label features
673
  vtkAxisActor* axis = this->PolarAxis;
674
675
676
677
  double delta = axis->GetDeltaMajor( VTK_AXIS_TYPE_X );
  double value = axis->GetMajorRangeStart();

  // Now create labels and polar arcs
678
  const char *format = this->PolarLabelFormat;
679
  char label[64];
680
  vtkIdType pointIdOffset = 0;
681
  for ( int  i = 0; i < this->NumberOfPolarAxisTicks; ++ i )
682
    {
683
    // Store label
684
    sprintf( label, format, value );
685
    labels->SetValue( i, label );
686

687
    if ( value  > 0. )
688
      {
689
      // Build corresponding polar arc for non-zero values
690
691
692
693
      double x1 = value * cosThetaMin;
      double y1 = value * sinThetaMin;
      double x2 = value * cosThetaMax;
      double y2 = value * sinThetaMax;
694
      vtkArcSource* arc = vtkArcSource::New();
695
      arc->SetCenter( O );
696
697
      arc->SetPoint1( O[0] + x1, O[1] + y1, O[2] );
      arc->SetPoint2( O[0] + x2, O[1] + y2, O[2] );
698
      arc->SetResolution( arcResolution );
699
      arc->SetNegative( angularSector > 180. );
700
      arc->Update();
Aashish Chaudhary's avatar
Aashish Chaudhary committed
701

702
703
704
705
706
707
708
709
710
711
      // 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
712

713
714
715
      // Clean up
      arc->Delete();
      delete [] arcPointIds;
Aashish Chaudhary's avatar
Aashish Chaudhary committed
716

717
718
      // Update polyline cell offset
      pointIdOffset += nPoints;
719
720
721
      }

    // Move to next value
722
    value += delta;
723
    }
724
725

  // Store labels
726
  this->PolarAxis->SetLabels( labels );
727
728

  // Clean up
729
  labels->Delete();
730
731
732

  // Update axis label followers
  vtkAxisFollower** labelActors = axis->GetLabelActors();
733
  for( int i = 0; i < this->NumberOfPolarAxisTicks; ++ i )
734
735
736
    {
    labelActors[i]->SetAxis( axis );
    labelActors[i]->SetScreenOffset( this->LabelScreenOffset );
737
738
    labelActors[i]->SetEnableDistanceLOD( this->EnableDistanceLOD );
    labelActors[i]->SetDistanceLODThreshold( .9 * this->DistanceLODThreshold );
739
    }
740
741
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
742
//-----------------------------------------------------------------------------
743
744
745
void vtkPolarAxesActor::AutoScale( vtkViewport *viewport )
{

746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
  // 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 );
    }
766
767

  // Loop over radial axes
768
769
  for ( int i = 0; i < this->NumberOfRadialAxes; ++ i )
    {
770
    axis = this->RadialAxes[i];
771
    // Scale title
772
773
774
775
776
777
    newTitleScale 
      = vtkAxisFollower::AutoScale( viewport, 
                                    this->Camera,
                                    this->ScreenSize,
                                    axis->GetTitleActor()->GetPosition() );
    axis->SetTitleScale( newTitleScale );
778
    }
779
780
}

781
782
783
784
785
786
787
788
789
790
791
792
793
//-----------------------------------------------------------------------------
void vtkPolarAxesActor::SetPolarAxisProperty( vtkProperty *prop )
{
  this->PolarAxisProperty->DeepCopy( prop );
  this->Modified();
}

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

Aashish Chaudhary's avatar
Aashish Chaudhary committed
794
//-----------------------------------------------------------------------------
Philippe Pébay's avatar
Philippe Pébay committed
795
void vtkPolarAxesActor::SetRadialAxesProperty( vtkProperty *prop )
796
{
Philippe Pébay's avatar
Philippe Pébay committed
797
  this->RadialAxesProperty->DeepCopy( prop );
798
799
800
  this->Modified();
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
801
//-----------------------------------------------------------------------------
802
803
804
805
vtkProperty* vtkPolarAxesActor::GetRadialAxesProperty()
{
  return this->RadialAxesProperty;
}
806

Aashish Chaudhary's avatar
Aashish Chaudhary committed
807
//-----------------------------------------------------------------------------
808
809
810
811
812
813
void vtkPolarAxesActor::SetPolarArcsProperty( vtkProperty *prop )
{
  this->PolarArcsActor->SetProperty(prop);
  this->Modified();
}

Aashish Chaudhary's avatar
Aashish Chaudhary committed
814
//-----------------------------------------------------------------------------
815
816
817
818
vtkProperty* vtkPolarAxesActor::GetPolarArcsProperty()
{
  return this->PolarArcsActor->GetProperty();
}