Changeset 3549


Ignore:
Timestamp:
Mar 22, 2013 11:16:51 AM (9 years ago)
Author:
ldelgass
Message:

Fix for oversized axis labels. AutoScale? computation in CubeAxesActor? happens
before label positions may be rebuilt (when rendering each AxisActor?), so
recompute AutoScale? in AxisActor? when rebuilding the axis.

Location:
trunk/packages/vizservers/vtkvis
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/vtkvis/vtkRpAxisActor.cpp

    r3479 r3549  
    176176  this->CalculateTitleOffset = 1;
    177177  this->CalculateLabelOffset = 1;
     178
     179  this->ScreenSize = 10.;
    178180
    179181  // Instance variables specific to 2D mode
     
    658660    }
    659661
     662  // If label positions changed, need to rescale
     663  this->AutoScale(viewport);
     664
    660665  this->LastAxisPosition = this->AxisPosition;
    661666
     
    778783    this->LabelActors[i]->SetPosition(pos[0], pos[1], pos[2]);
    779784    }
     785}
     786
     787void
     788vtkRpAxisActor::AutoScale(vtkViewport *viewport)
     789{
     790    double newTitleScale
     791        = this->AutoScale(viewport,
     792                          this->ScreenSize,
     793                          this->GetTitleActor()->GetPosition());
     794
     795    this->SetTitleScale(newTitleScale);
     796
     797    // Now labels.
     798    vtkRpAxisFollower** labelActors = this->GetLabelActors();
     799
     800    for(int j = 0; j < this->GetNumberOfLabelsBuilt(); ++j)
     801      {
     802      double newLabelScale
     803        = this->AutoScale(viewport,
     804                          this->ScreenSize,
     805                          labelActors[j]->GetPosition());
     806
     807      labelActors[j]->SetScale(newLabelScale);
     808      }
     809}
     810
     811double
     812vtkRpAxisActor::AutoScale(vtkViewport *viewport, double screenSize,
     813                          double position[3])
     814{
     815  double factor = 1;
     816  if (viewport->GetSize()[1] > 0)
     817    {
     818    factor = 2.0 * screenSize
     819      * tan(vtkMath::RadiansFromDegrees(this->Camera->GetViewAngle()/2.0))
     820      / viewport->GetSize()[1];
     821    }
     822
     823    double dist = sqrt(
     824          vtkMath::Distance2BetweenPoints(position,
     825                                          this->Camera->GetPosition()));
     826    double newScale = factor * dist;
     827
     828    return newScale;
    780829}
    781830
  • trunk/packages/vizservers/vtkvis/vtkRpAxisActor.h

    r3479 r3549  
    123123  void   GetBounds(double bounds[6]);
    124124
     125  vtkSetMacro(ScreenSize, double);
     126  vtkGetMacro(ScreenSize, double);
     127
    125128  // Description:
    126129  // Set/Get the format with which to print the labels on the axis.
     
    466469  void TransformBounds(vtkViewport *, double bnds[6]);
    467470
     471  void AutoScale(vtkViewport *viewport);
     472  double AutoScale(vtkViewport *viewport, double screenSize,
     473                   double position[3]);
     474
    468475  void BuildLabels(vtkViewport *, bool);
    469476  void BuildLabels2D(vtkViewport *, bool);
     
    552559  int                 CalculateLabelOffset;
    553560
     561  double              ScreenSize;
     562
    554563  // Description:
    555564  // Use xy-axis only when Use2DMode=1:
  • trunk/packages/vizservers/vtkvis/vtkRpCubeAxesActor.cpp

    r3496 r3549  
    2929#include "vtkViewport.h"
    3030
    31 
    3231vtkStandardNewMacro(vtkRpCubeAxesActor);
    3332vtkCxxSetObjectMacro(vtkRpCubeAxesActor, Camera,vtkCamera);
     
    117116  //this->YAxesGridpolysProperty->LightingOff();       // To be able to see the polys from high camera angles
    118117  //this->ZAxesGridpolysProperty->LightingOff();       // To be able to see the polys from high camera angles
     118
     119  this->ScreenSize = 10.0;
     120
     121  this->LabelScreenOffset = 20.0 + this->ScreenSize * 0.5;
     122  this->TitleScreenOffset =
     123    this->LabelScreenOffset * 2.0 + this->ScreenSize * 0.5;
    119124
    120125  for (int i = 0; i < NUMBER_OF_ALIGNED_AXIS; i++)
     
    133138    this->XAxes[i]->SetCalculateTitleOffset(0);
    134139    this->XAxes[i]->SetCalculateLabelOffset(0);
     140    this->XAxes[i]->SetScreenSize(this->ScreenSize);
    135141
    136142    this->YAxes[i] = vtkRpAxisActor::New();
     
    147153    this->YAxes[i]->SetCalculateTitleOffset(0);
    148154    this->YAxes[i]->SetCalculateLabelOffset(0);
     155    this->YAxes[i]->SetScreenSize(this->ScreenSize);
    149156
    150157    this->ZAxes[i] = vtkRpAxisActor::New();
     
    161168    this->ZAxes[i]->SetCalculateTitleOffset(0);
    162169    this->ZAxes[i]->SetCalculateLabelOffset(0);
    163 
    164     this->ScreenSize = 10.0;
    165 
    166     this->LabelScreenOffset = 20.0 + this->ScreenSize * 0.5;
    167     this->TitleScreenOffset =
    168       this->LabelScreenOffset * 2.0 + this->ScreenSize * 0.5;
     170    this->ZAxes[i]->SetScreenSize(this->ScreenSize);
    169171
    170172    // Pass information to axes followers.
     
    680682  for (int i = 0; i < NUMBER_OF_ALIGNED_AXIS; i++)
    681683    {
     684    this->XAxes[i]->SetScreenSize(this->ScreenSize);
     685    this->YAxes[i]->SetScreenSize(this->ScreenSize);
     686    this->ZAxes[i]->SetScreenSize(this->ScreenSize);
     687
    682688    this->XAxes[i]->GetTitleActor()->SetScreenOffset(this->TitleScreenOffset);
    683689    this->YAxes[i]->GetTitleActor()->SetScreenOffset(this->TitleScreenOffset);
Note: See TracChangeset for help on using the changeset viewer.