Commit 1e8e1afa authored by Aashish Chaudhary's avatar Aashish Chaudhary
Browse files

ENH: Removed code duplication

Change-Id: Ibc7c141970ffc199a321b817369323fd5a2e0296
parent ff36eb88
......@@ -197,32 +197,32 @@ void vtkAxisFollower::CalculateOrthogonalVectors(double rX[3], double rY[3],
//----------------------------------------------------------------------------
double vtkAxisFollower::AutoScale(vtkViewport *viewport, vtkCamera *camera,
double screenOffset, double position[3])
double screenSize, double position[3])
{
double newScale = 0.0;
if(!viewport)
{
vtkErrorMacro("Invalid or NULL viewport \n");
std::cerr << "Invalid or NULL viewport \n";
return newScale;
}
if(!camera)
{
vtkErrorMacro("Invalid or NULL camera \n");
std::cerr << "Invalid or NULL camera \n";
return newScale;
}
if(!position)
{
vtkErrorMacro("Invalid or NULL position \n");
std::cerr << "Invalid or NULL position \n";
return newScale;
}
double factor = 1;
if (viewport->GetSize()[1] > 0)
{
factor = 2.0 * screenOffset
factor = 2.0 * screenSize
* tan(vtkMath::RadiansFromDegrees(camera->GetViewAngle()/2.0))
/ viewport->GetSize()[1];
}
......
......@@ -108,6 +108,12 @@ public:
// Shallow copy of a follower. Overloads the virtual vtkProp method.
void ShallowCopy(vtkProp *prop);
// Description:
// Calculate scale factor to maintain same size of a object
// on the screen.
static double AutoScale(vtkViewport *viewport, vtkCamera * camera,
double screenSize, double position[3]);
protected:
vtkAxisFollower();
~vtkAxisFollower();
......@@ -116,8 +122,6 @@ protected:
vtkAxisActor *axis1, double *dop,
vtkRenderer *ren);
double AutoScale(vtkViewport *viewport, vtkCamera * camera,
double screenOffset, double position[3]);
void ComputeRotationAndTranlation(vtkRenderer *ren, double translation[3],
double Rx[3], double Ry[3], double Rz[3],
......
......@@ -855,9 +855,8 @@ void vtkPolarAxesActor::AutoScale( vtkViewport *viewport,
for ( int i = 0; i < this->NumberOfRadialAxes; ++ i )
{
// Scale title
newTitleScale = this->AutoScale( viewport,
this->ScreenSize,
axis[i]->GetTitleActor()->GetPosition() );
newTitleScale = vtkAxisFollower::AutoScale( viewport, this->Camera,
this->ScreenSize, axis[i]->GetTitleActor()->GetPosition() );
axis[i]->SetTitleScale( newTitleScale );
......@@ -866,36 +865,14 @@ void vtkPolarAxesActor::AutoScale( vtkViewport *viewport,
for( int j = 0; j < axis[i]->GetNumberOfLabelsBuilt(); ++ j )
{
double newLabelScale = this->AutoScale( viewport,
this->ScreenSize,
labelActors[j]->GetPosition() );
double newLabelScale = vtkAxisFollower::AutoScale( viewport,
this->Camera, 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 )
{
......
......@@ -235,7 +235,6 @@ protected:
void AutoScale( vtkViewport* viewport );
void AutoScale( vtkViewport* viewport, vtkAxisActor** axes );
double AutoScale( vtkViewport* viewport, double screenSize, double position[3] );
// Description:
// Coordinates of the pole
......
Markdown is supported
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