Commit c7b4ec1c authored by Philippe Pébay's avatar Philippe Pébay
Browse files

Proper scaling of radial axes; added an option for auto-scaling

Change-Id: I1348f235e41bb041e3a381f4ed048b54da819df7
parent 5978154b
......@@ -81,7 +81,7 @@ int TestPolarAxes( int argc, char * argv [] )
vtkNew<vtkPolarAxesActor> polaxes;
polaxes->SetBounds( normals->GetOutput()->GetBounds() );
polaxes->SetPole( -3., 0., 2. );
polaxes->SetMaximumRadius( 300 );
polaxes->SetAutoScaleRadius( true );
polaxes->SetCamera( renderer->GetActiveCamera() );
polaxes->SetRadialLabelFormat( "%6.1f" );
polaxes->GetRadialAxesProperty()->SetColor( .0, .0, .9 );
......
......@@ -52,6 +52,7 @@ void vtkPolarAxesActor::PrintSelf( ostream& os, vtkIndent indent )
<< this->Pole[2] << " )\n";
os << indent << "Maximum Radius" << this->MaximumRadius << endl;
os << indent << "Auto-Scale Radius" << this->AutoScaleRadius << endl;
os << indent << "Maximum Angle" << this->MaximumAngle << endl;
......@@ -107,6 +108,9 @@ vtkPolarAxesActor::vtkPolarAxesActor() : vtkActor()
// Default maximum polar radius
this->MaximumRadius = VTK_DOUBLE_MAX;
// Do not auto-scale radius by default
this->AutoScaleRadius = false;
// Default maximum polar angle
this->MaximumAngle = VTK_DEFAULT_MAXIMUM_POLAR_ANGLE;
......@@ -419,12 +423,18 @@ void vtkPolarAxesActor::BuildAxes( vtkViewport *viewport )
{
o[i] = this->Pole[i] == VTK_DOUBLE_MAX ? bounds[i * 2] : this->Pole[i];
}
// 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
|| this->MaximumRadius < 1.e-6 * ls
|| this->MaximumRadius > 1.e6 * ls )
{
this->MaximumRadius = .5 * ls;
}
// Prepare axes for rendering with user-definable options
// FIXME
double rho = bounds[1] - bounds[0];
double dAlpha = this->MaximumAngle / ( this->NumberOfRadialAxes - 1. );
this->ComputePolarAxisTicks( this->RadialAxes[0], bounds[0], bounds[1] );
// this->BuildLabels( this->RadialAxes );
......@@ -436,14 +446,14 @@ void vtkPolarAxesActor::BuildAxes( vtkViewport *viewport )
double theta = i * dAlpha;
double thetaRad = vtkMath::RadiansFromDegrees( theta );
vtkAxisActor* axis = this->RadialAxes[i];
double x = o[0] + rho * cos( thetaRad );
double y = o[1] + rho * sin( thetaRad );
double x = o[0] + this->MaximumRadius * cos( thetaRad );
double y = o[1] + this->MaximumRadius * sin( thetaRad );
axis->GetPoint1Coordinate()->SetValue( o[0], o[1], o[2] );
axis->GetPoint2Coordinate()->SetValue( x, y, o[2] );
// Set axis ticks
axis->SetRange( 0., rho );
axis->SetMajorTickSize( .02 * rho );
axis->SetRange( 0., this->MaximumRadius );
axis->SetMajorTickSize( .02 * this->MaximumRadius );
// Set axis title
vtksys_ios::ostringstream thetaStream;
......
......@@ -74,6 +74,12 @@ public:
vtkSetMacro( MaximumRadius, double );
vtkGetMacro( MaximumRadius, double );
// Description:
// Turn on and off the auto-scaling of the maximum radius.
vtkSetMacro( AutoScaleRadius,int );
vtkGetMacro( AutoScaleRadius,int );
vtkBooleanMacro( AutoScaleRadius,int );
// Description:
// Set/Get the maximum radius of the polar coordinates.
// Default: VTK_DEFAULT_MAXIMUM_POLAR_ANGLE
......@@ -226,6 +232,10 @@ protected:
// Maximum polar radius (minimum is always 0)
double MaximumRadius;
// Description:
// Auto-scale polar radius (with respect to average length scale of x-y bounding box)
bool AutoScaleRadius;
// Description:
// Maximum polar angle (minimum is always 0)
double MaximumAngle;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment