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

Now placing labels along polar axis

Change-Id: Iaf34f95c0d36fcc5460f34c331ed0a66cfbd033e
parent 7e8d73c0
......@@ -436,8 +436,6 @@ void vtkPolarAxesActor::BuildAxes( vtkViewport *viewport )
// Prepare axes for rendering with user-definable options
double dAlpha = this->MaximumAngle / ( this->NumberOfRadialAxes - 1. );
// this->UpdateLabels( this->RadialAxes );
// Set radial axes
for ( int i = 0; i < this->NumberOfRadialAxes; ++ i )
{
......@@ -650,64 +648,6 @@ void vtkPolarAxesActor::BuildPolarAxisTicks( double origin )
axis->SetDeltaMajor( VTK_AXIS_TYPE_X, major );
}
// ****************************************************************
void vtkPolarAxesActor::AutoScale( vtkViewport *viewport )
{
// Current implementation only for perspective projections.
this->AutoScale( viewport, this->RadialAxes );
}
// ****************************************************************
void vtkPolarAxesActor::AutoScale( vtkViewport *viewport,
vtkAxisActor** axis )
{
double newTitleScale = this->TitleScale;
// Loop over radial axes
for ( int i = 0; i < this->NumberOfRadialAxes; ++ i )
{
// Scale title
newTitleScale = this->AutoScale( viewport,
this->ScreenSize,
axis[i]->GetTitleActor()->GetPosition() );
axis[i]->SetTitleScale( newTitleScale );
// Scale labels
vtkAxisFollower** labelActors = axis[i]->GetLabelActors();
for( int j = 0; j < axis[i]->GetNumberOfLabelsBuilt(); ++ j )
{
double newLabelScale = this->AutoScale( viewport,
this->ScreenSize,
labelActors[j]->GetPosition() );
labelActors[j]->SetScale( newLabelScale );
}
}
}
// ****************************************************************
double vtkPolarAxesActor::AutoScale( vtkViewport *viewport,
double screenSize,
double position[3] )
{
double factor = 1;
if ( viewport->GetSize()[1] > 0 )
{
factor = 2.0 * screenSize
* tan( vtkMath::RadiansFromDegrees( this->Camera->GetViewAngle()/2.0 ) )
/ viewport->GetSize()[1];
}
double dist = sqrt(
vtkMath::Distance2BetweenPoints( position,
this->Camera->GetPosition() ));
double newScale = factor * dist;
return newScale;
}
// ****************************************************************
void vtkPolarAxesActor::BuildPolarAxisLabels( double origin )
{
......@@ -717,14 +657,14 @@ void vtkPolarAxesActor::BuildPolarAxisLabels( double origin )
double val = axis->GetMajorStart( VTK_AXIS_TYPE_X );
const double *p2 = axis->GetPoint2Coordinate()->GetValue();
double lastVal = p2[0];
int labelCount = 0;
while ( val <= lastVal && labelCount < VTK_MAX_LABELS )
vtkIdType nLabels = 0;
while ( val <= lastVal && nLabels < VTK_MAX_LABELS )
{
++ labelCount;
++ nLabels;
val += deltaMajor;
}
vtkStringArray *labels = vtkStringArray::New();
labels->SetNumberOfValues( labelCount );
labels->SetNumberOfValues( nLabels );
// Calculate scale factor
double scaleFactor = 1.;
......@@ -733,14 +673,13 @@ void vtkPolarAxesActor::BuildPolarAxisLabels( double origin )
{
scaleFactor = 1. / pow( 10., lastPow );
}
cerr << "Scale factor: " << scaleFactor << endl;
// Now create labels
val = axis->GetMajorRangeStart();
deltaMajor = axis->GetDeltaRangeMajor();
const char *format = this->RadialLabelFormat;
char label[64];
for ( int i = 0; i < labelCount; ++ i )
for ( int i = 0; i < nLabels; ++ i )
{
if ( fabs( val ) < .01 && this->MaximumRadius > 1 )
{
......@@ -788,7 +727,6 @@ void vtkPolarAxesActor::BuildPolarAxisLabels( double origin )
}
}
labels->SetValue( i, label );
cerr << "label " << i << " is " << label << endl;
val += deltaMajor;
}
......@@ -797,6 +735,14 @@ void vtkPolarAxesActor::BuildPolarAxisLabels( double origin )
// Clean up
labels->Delete();
// Update axis label followers
vtkAxisFollower** labelActors = axis->GetLabelActors();
for( int i = 0; i < nLabels; ++i )
{
labelActors[i]->SetAxis( axis );
labelActors[i]->SetScreenOffset( this->LabelScreenOffset );
}
}
// ****************************************************************************
......@@ -810,20 +756,64 @@ void vtkPolarAxesActor::SetLabelScaling( bool autoscale, int upow )
}
}
// ****************************************************************************
void vtkPolarAxesActor::UpdateLabels( vtkAxisActor** axis )
{
// ****************************************************************
void vtkPolarAxesActor::AutoScale( vtkViewport *viewport )
{
// Current implementation only for perspective projections.
this->AutoScale( viewport, this->RadialAxes );
}
// ****************************************************************
void vtkPolarAxesActor::AutoScale( vtkViewport *viewport,
vtkAxisActor** axis )
{
double newTitleScale = this->TitleScale;
// Loop over radial axes
for ( int i = 0; i < this->NumberOfRadialAxes; ++ i )
{
int numberOfLabelsBuilt = axis[i]->GetNumberOfLabelsBuilt();
// Scale title
newTitleScale = this->AutoScale( viewport,
this->ScreenSize,
axis[i]->GetTitleActor()->GetPosition() );
axis[i]->SetTitleScale( newTitleScale );
// Scale labels
vtkAxisFollower** labelActors = axis[i]->GetLabelActors();
for( int k = 0; k < numberOfLabelsBuilt; ++ k )
for( int j = 0; j < axis[i]->GetNumberOfLabelsBuilt(); ++ j )
{
labelActors[k]->SetAxis( this->RadialAxes[i] );
labelActors[k]->SetScreenOffset( this->LabelScreenOffset );
double newLabelScale = this->AutoScale( viewport,
this->ScreenSize,
labelActors[j]->GetPosition() );
labelActors[j]->SetScale( newLabelScale );
}
}
}
}
// ****************************************************************
double vtkPolarAxesActor::AutoScale( vtkViewport *viewport,
double screenSize,
double position[3] )
{
double factor = 1;
if ( viewport->GetSize()[1] > 0 )
{
factor = 2.0 * screenSize
* tan( vtkMath::RadiansFromDegrees( this->Camera->GetViewAngle()/2.0 ) )
/ viewport->GetSize()[1];
}
double dist = sqrt(
vtkMath::Distance2BetweenPoints( position,
this->Camera->GetPosition() ));
double newScale = factor * dist;
return newScale;
}
// ****************************************************************************
void vtkPolarAxesActor::SetRadialAxesProperty( vtkProperty *prop )
{
......
......@@ -192,10 +192,6 @@ protected:
// and thus do not need to be set very often.
void SetNonDependentAttributes(void );
void AutoScale( vtkViewport* viewport );
void AutoScale( vtkViewport* viewport, vtkAxisActor** axes );
double AutoScale( vtkViewport* viewport, double screenSize, double position[3] );
// Description:
// Prepare ticks on polar axis.
// Determine how many ticks are needed create them.
......@@ -215,9 +211,9 @@ void BuildPolarAxisTicks( double );
double FFix(double );
double FSign(double, double );
// Description:
// Set axes and screen size of the labels
void UpdateLabels( vtkAxisActor **axis );
void AutoScale( vtkViewport* viewport );
void AutoScale( vtkViewport* viewport, vtkAxisActor** axes );
double AutoScale( vtkViewport* viewport, double screenSize, double position[3] );
// Description:
// Coordinates of the pole
......
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