Ignore:
Timestamp:
Aug 9, 2015, 3:59:03 PM (9 years ago)
Author:
ldelgass
Message:

Update custom cube axes: rebase on version in VTK 6.1.0 plus backported fixes
from 6.3.0rc1, but without TextActor3D option.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vtkvis/trunk/vtkRpAxisActor.cpp

    r3549 r5802  
    22
    33  Program:   Visualization Toolkit
    4   Module:    vtkRpAxisActor.cpp
     4  Module:    vtkRpAxisActor.cxx
    55  Thanks:    Kathleen Bonnell, B Division, Lawrence Livermore Nat'l Laboratory
    66
     
    3232#include "vtkVectorText.h"
    3333#include "vtkViewport.h"
     34#include "vtkVersion.h"
     35#include "vtkWindow.h"
    3436
    3537vtkStandardNewMacro(vtkRpAxisActor);
     
    6062  this->Range[0] = 0.0;
    6163  this->Range[1] = 1.0;
     64  this->ScreenSize = 10.;
     65  this->LabelOffset = 20.;
     66  this->TitleOffset = 20.;
    6267
    6368  this->Bounds[0] = this->Bounds[2] = this->Bounds[4] = -1;
     
    7075  this->TitleTextProperty->SetColor(0.,0.,0.);
    7176  this->TitleTextProperty->SetFontFamilyToArial();
    72   this->TitleTextProperty->SetFontSize(14);
     77  this->TitleTextProperty->SetFontSize(18);
     78  this->TitleTextProperty->SetVerticalJustificationToCentered();
     79  this->TitleTextProperty->SetJustificationToCentered();
    7380
    7481  this->TitleVector = vtkVectorText::New();
     
    7784    this->TitleVector->GetOutputPort());
    7885  this->TitleActor = vtkRpAxisFollower::New();
     86  this->TitleActor->SetAxis(this);
    7987  this->TitleActor->SetMapper(this->TitleMapper);
    8088  this->TitleActor->SetEnableDistanceLOD(0);
     
    9098  this->LabelTextProperty->SetColor(0.,0.,0.);
    9199  this->LabelTextProperty->SetFontFamilyToArial();
    92   this->LabelTextProperty->SetFontSize(12);
     100  this->LabelTextProperty->SetFontSize(14);
     101  this->LabelTextProperty->SetVerticalJustificationToBottom();
     102  this->LabelTextProperty->SetJustificationToLeft();
    93103
    94104  this->AxisLines = vtkPolyData::New();
     
    177187  this->CalculateLabelOffset = 1;
    178188
    179   this->ScreenSize = 10.;
    180 
    181189  // Instance variables specific to 2D mode
    182190  this->Use2DMode = 0;
     
    221229    }
    222230
    223   if (this->LabelFormat)
    224     {
    225     delete [] this->LabelFormat;
    226     this->LabelFormat = NULL;
    227     }
     231  delete [] this->LabelFormat;
     232  this->LabelFormat = NULL;
    228233
    229234  if (this->TitleVector)
     
    248253    }
    249254
    250   if (this->Title)
    251     {
    252     delete [] this->Title;
    253     this->Title = NULL;
    254     }
     255  delete [] this->Title;
     256  this->Title = NULL;
    255257
    256258  if (this->TitleTextProperty)
     
    410412    if (this->Title != NULL && this->Title[0] != 0 && this->TitleVisibility)
    411413      {
    412       if (this->Use2DMode == 0)
     414      if (this->Use2DMode)
     415        {
     416        renderedSomething += this->TitleActor2D->RenderOpaqueGeometry(viewport);
     417        }
     418      else
    413419        {
    414420        renderedSomething += this->TitleActor->RenderOpaqueGeometry(viewport);
    415421        }
    416       else
    417         {
    418         renderedSomething += this->TitleActor2D->RenderOpaqueGeometry(viewport);
    419         }
    420422      }
    421423    if (this->AxisVisibility || this->TickVisibility)
     
    435437      for (i=0; i<this->NumberOfLabelsBuilt; i++)
    436438        {
    437         if (this->Use2DMode == 0)
     439        if (this->Use2DMode)
     440          {
     441          renderedSomething +=
     442            this->LabelActors2D[i]->RenderOpaqueGeometry(viewport);
     443          }
     444        else
    438445          {
    439446          renderedSomething +=
    440447            this->LabelActors[i]->RenderOpaqueGeometry(viewport);
    441448          }
    442         else
    443           {
    444           renderedSomething +=
    445             this->LabelActors2D[i]->RenderOpaqueGeometry(viewport);
    446           }
    447449        }
    448450      }
     
    478480      renderedSomething += this->GridpolysActor->RenderTranslucentPolygonalGeometry(viewport);
    479481      }
    480     }
    481 
     482    if (this->Title != NULL && this->Title[0] != 0 && this->TitleVisibility)
     483      {
     484      if (this->Use2DMode)
     485        {
     486        renderedSomething += this->TitleActor2D->RenderTranslucentPolygonalGeometry(viewport);
     487        }
     488      else
     489        {
     490        renderedSomething += this->TitleActor->RenderTranslucentPolygonalGeometry(viewport);
     491        }
     492      }
     493    if (this->LabelVisibility)
     494      {
     495      for (int i=0; i<this->NumberOfLabelsBuilt; i++)
     496        {
     497        if (this->Use2DMode)
     498          {
     499          renderedSomething +=
     500            this->LabelActors2D[i]->RenderTranslucentPolygonalGeometry(viewport);
     501          }
     502        else
     503          {
     504          renderedSomething +=
     505            this->LabelActors[i]->RenderTranslucentPolygonalGeometry(viewport);
     506          }
     507        }
     508      }
     509    }
    482510  return renderedSomething;
    483511}
     
    493521  if (!this->AxisHasZeroLength && !this->DrawGridlinesOnly)
    494522    {
    495     if( this->Use2DMode == 1 )
     523    if (this->Use2DMode)
    496524      {
    497525      renderedSomething += this->TitleActor2D->RenderOverlay(viewport);
     526      }
     527    else
     528      {
     529      renderedSomething += this->TitleActor->RenderOverlay(viewport);
    498530      }
    499531    if (this->LabelVisibility)
     
    501533      for (i=0; i<this->NumberOfLabelsBuilt; i++)
    502534        {
    503         if (this->Use2DMode == 1)
     535        if (this->Use2DMode)
    504536          {
    505537          renderedSomething += this->LabelActors2D[i]->RenderOverlay(viewport);
     538          }
     539        else
     540          {
     541          renderedSomething += this->LabelActors[i]->RenderOverlay(viewport);
    506542          }
    507543        }
     
    578614
    579615    if (this->DrawGridpolys &&
    580         this-GridpolysActor->HasTranslucentPolygonalGeometry())
     616        this->GridpolysActor->HasTranslucentPolygonalGeometry())
    581617      {
    582618      return 1;
     
    627663    this->TitleActor->SetProperty(this->GetProperty());
    628664    this->TitleActor->GetProperty()->SetColor(this->TitleTextProperty->GetColor());
     665    this->TitleActor->GetProperty()->SetOpacity(this->TitleTextProperty->GetOpacity());
    629666    }
    630667
     
    660697    }
    661698
    662   // If label positions changed, need to rescale
    663   this->AutoScale(viewport);
    664 
    665699  this->LastAxisPosition = this->AxisPosition;
    666700
     
    686720    this->LabelActors[i]->SetProperty(this->GetProperty());
    687721    this->LabelActors[i]->GetProperty()->SetColor(this->LabelTextProperty->GetColor());
     722    this->LabelActors[i]->GetProperty()->SetOpacity(this->LabelTextProperty->GetOpacity());
    688723    this->LabelActors[i]->SetOrientation(0., 0., this->LabelTextProperty->GetOrientation());
    689724
     
    703738}
    704739
    705 int vtkRpAxisActorMultiplierTable1[4] = { -1, -1, 1,  1};
    706 int vtkRpAxisActorMultiplierTable2[4] = { -1,  1, 1, -1};
     740static const int vtkRpAxisActorMultiplierTable1[4] = { -1, -1, 1,  1};
     741static const int vtkRpAxisActorMultiplierTable2[4] = { -1,  1, 1, -1};
    707742
    708743// *******************************************************************
     
    716751    }
    717752
    718   double bounds[6], center[3], tick[3], pos[3], scale[3];
     753  double bounds[6], center[3], tick[3], pos[3];
    719754  int i = 0;
    720755  int xmult = 0;
    721756  int ymult = 0;
     757  double labelAngle = vtkMath::RadiansFromDegrees(this->LabelTextProperty->GetOrientation());
     758  double labelCos = fabs(cos(labelAngle));
     759  double labelSin = fabs(sin(labelAngle));
     760
    722761
    723762  switch (this->AxisType)
     
    755794
    756795    this->LabelActors[i]->GetMapper()->GetBounds(bounds);
    757     this->LabelActors[i]->GetScale(scale);
    758796
    759797    if(this->CalculateLabelOffset)
    760798      {
    761       double halfWidth  = (bounds[1] - bounds[0]) * 0.5 * scale[0];
    762       double halfHeight = (bounds[3] - bounds[2]) * 0.5 * scale[1];
     799      double halfWidth  = 0.5 * ((bounds[1] - bounds[0]) * labelCos + (bounds[3] - bounds[2]) * labelSin);
     800      double halfHeight = 0.5 * ((bounds[1] - bounds[0]) * labelSin + (bounds[3] - bounds[2]) * labelCos);
    763801
    764802      center[0] = tick[0] + xmult * (halfWidth  + this->MinorTickSize);
     
    772810    else
    773811      {
    774       center[0] = tick[0] ;
    775       center[1] = tick[1];
    776       center[2] = tick[2];
    777 
    778       pos[0] = center[0];
    779       pos[1] = center[1];
    780       pos[2] = center[2];
     812      pos[0] = tick[0];
     813      pos[1] = tick[1];
     814      pos[2] = tick[2];
     815
     816      double delta  = 0.5 * ((bounds[1] - bounds[0]) * labelSin + (bounds[3] - bounds[2]) * labelCos);
     817      this->LabelActors[i]->SetScreenOffset(this->LabelOffset + (delta) * this->ScreenSize);
    781818      }
    782819
    783820    this->LabelActors[i]->SetPosition(pos[0], pos[1], pos[2]);
    784821    }
    785 }
    786 
    787 void
    788 vtkRpAxisActor::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 
    811 double
    812 vtkRpAxisActor::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;
    829822}
    830823
     
    841834    {
    842835    this->LabelActors2D[i]->GetProperty()->SetColor(this->LabelTextProperty->GetColor());
    843     this->LabelActors2D[i]->GetProperty()->SetOpacity(1);
    844     this->LabelActors2D[i]->GetTextProperty()->SetFontSize(this->LabelTextProperty->GetFontSize());
    845     this->LabelActors2D[i]->GetTextProperty()->SetVerticalJustificationToBottom();
    846     this->LabelActors2D[i]->GetTextProperty()->SetJustificationToLeft();
     836    this->LabelActors2D[i]->GetProperty()->SetOpacity(this->LabelTextProperty->GetOpacity());
     837    this->LabelActors2D[i]->GetTextProperty()->ShallowCopy(this->LabelTextProperty);
    847838    }
    848839
     
    906897    return;
    907898    }
    908 
     899#if VTK_MAJOR_VERSION == 6 && VTK_MINOR_VERSION >= 3
     900  vtkWindow *win = viewport->GetVTKWindow();
     901  if (!win)
     902    {
     903    vtkErrorMacro(<<"No render window available: cannot determine DPI.");
     904    return;
     905    }
     906
     907#endif
    909908  for (int i = 0; i < this->NumberOfLabelsBuilt; i++)
    910909    {
     
    923922    int bbox[4];
    924923    if (!tren->GetBoundingBox(this->LabelActors2D[i]->GetTextProperty(),
     924#if VTK_MAJOR_VERSION == 6 && VTK_MINOR_VERSION >= 3
     925                              this->LabelActors2D[i]->GetInput(), bbox,
     926                              win->GetDPI()))
     927#else
    925928                              this->LabelActors2D[i]->GetInput(), bbox))
     929#endif
    926930      {
    927931      vtkErrorMacro(<< "Unable to calculate bounding box for label "
     
    951955    return;
    952956    }
    953   double labBounds[6], titleBounds[6], center[3], pos[3], scale[3];
     957  double labBounds[6], titleBounds[6], center[3], pos[3];
    954958  double labHeight, maxHeight = 0, labWidth, maxWidth = 0;
    955959  double halfTitleWidth, halfTitleHeight;
     960  double labelAngle = vtkMath::RadiansFromDegrees(this->LabelTextProperty->GetOrientation());
     961  double labelCos = fabs(cos(labelAngle));
     962  double labelSin = fabs(sin(labelAngle));
    956963
    957964  double *p1 = this->Point1Coordinate->GetValue();
     
    991998    {
    992999    this->LabelActors[i]->GetMapper()->GetBounds(labBounds);
    993     this->LabelActors[i]->GetScale(scale);
    994     labWidth = (labBounds[1] - labBounds[0])*scale[0];
     1000    labWidth = (labBounds[1] - labBounds[0]) * labelCos + (labBounds[3] - labBounds[2]) * labelSin;
    9951001    maxWidth = (labWidth > maxWidth ? labWidth : maxWidth);
    996     labHeight = (labBounds[3] - labBounds[2])*scale[1];
     1002    labHeight = (labBounds[1] - labBounds[0]) * labelSin + (labBounds[3] - labBounds[2]) * labelCos;
    9971003    maxHeight = (labHeight > maxHeight ? labHeight : maxHeight);
    9981004    }
     
    10021008  this->TitleActor->GetProperty()->SetColor(this->TitleTextProperty->GetColor());
    10031009  this->TitleActor->SetCamera(this->Camera);
    1004   this->TitleActor->SetPosition(p2[0], p2[1], p2[2]);
    10051010  this->TitleActor->GetMapper()->GetBounds(titleBounds);
    1006   this->TitleActor->GetScale(scale);
     1011
    10071012  if(!this->GetCalculateTitleOffset())
    10081013    {
     
    10141019  center[2] = p1[2] + (p2[2] - p1[2]) / 2.0;
    10151020
     1021  halfTitleHeight = (titleBounds[3] - titleBounds[2]) * 0.5;
    10161022  if(this->CalculateTitleOffset)
    10171023    {
    1018     halfTitleWidth  = (titleBounds[1] - titleBounds[0]) * 0.5 * scale[0];
    1019     halfTitleHeight = (titleBounds[3] - titleBounds[2]) * 0.5 * scale[1];
     1024    halfTitleWidth  = (titleBounds[1] - titleBounds[0]) * 0.5;
    10201025    center[0] += xmult * (halfTitleWidth + maxWidth);
    10211026    center[1] += ymult * (halfTitleHeight + 2*maxHeight);
     1027    }
     1028  else
     1029    {
     1030    this->TitleActor->SetScreenOffset(this->TitleOffset +
     1031      this->LabelOffset + this->ScreenSize * (maxHeight + halfTitleHeight));
    10221032    }
    10231033
     
    10441054  this->TitleActor2D->SetInput( this->TitleVector->GetText() );
    10451055  this->TitleActor2D->GetProperty()->SetColor( this->TitleTextProperty->GetColor() );
    1046   this->TitleActor2D->GetProperty()->SetOpacity(1);
    1047   this->TitleActor2D->GetTextProperty()->SetFontSize( this->TitleTextProperty->GetFontSize() );
    1048   this->TitleActor2D->GetTextProperty()->SetVerticalJustificationToCentered();
    1049   this->TitleActor2D->GetTextProperty()->SetJustificationToCentered();
     1056  this->TitleActor2D->GetProperty()->SetOpacity( this->TitleTextProperty->GetOpacity() );
     1057  this->TitleActor2D->GetTextProperty()->ShallowCopy(this->TitleTextProperty);
    10501058
    10511059  if (this->AxisType == VTK_AXIS_TYPE_Y)
     
    12731281  //
    12741282  int i, numLabels = labels->GetNumberOfValues();
     1283  if (numLabels < 0)
     1284    {
     1285    vtkErrorMacro(<< "Number of labels " << numLabels << " is invalid");
     1286    return;
     1287    }
    12751288  if (this->NumberOfLabelsBuilt != numLabels)
    12761289    {
     
    13021315        this->LabelVectors[i]->GetOutputPort());
    13031316      this->LabelActors[i] = vtkRpAxisFollower::New();
     1317      this->LabelActors[i]->SetAxis(this);
    13041318      this->LabelActors[i]->SetMapper(this->LabelMappers[i]);
    13051319      this->LabelActors[i]->SetEnableDistanceLOD(0);
     
    13071321      this->LabelActors[i]->GetProperty()->SetDiffuse(0.);
    13081322      this->LabelActors[i]->GetProperty()->SetColor(this->LabelTextProperty->GetColor());
     1323      this->LabelActors[i]->GetProperty()->SetOpacity(this->LabelTextProperty->GetOpacity());
    13091324      this->LabelActors2D[i] = vtkTextActor::New();
    13101325      }
     
    14611476// *********************************************************************
    14621477void
    1463 vtkRpAxisActor::SetBounds(double b[6])
     1478vtkRpAxisActor::SetBounds(const double b[6])
    14641479{
    14651480  if ((this->Bounds[0] != b[0]) ||
     
    15371552    this->LabelActors[i]->SetProperty(newProp);
    15381553    this->LabelActors[i]->GetMapper()->GetBounds(bounds);
    1539     this->LabelActors[i]->GetProperty()->SetColor(this->LabelTextProperty->GetColor());
    15401554    xsize = bounds[1] - bounds[0];
    15411555    ysize = bounds[3] - bounds[2];
     
    15621576  newProp->Delete();
    15631577  this->TitleActor->GetMapper()->GetBounds(bounds);
    1564   this->TitleActor->GetProperty()->SetColor(this->TitleTextProperty->GetColor());
    15651578  xsize = bounds[1] - bounds[0];
    15661579  ysize = bounds[3] - bounds[2];
     
    15751588  for (int i=0; i < this->NumberOfLabelsBuilt; i++)
    15761589    {
    1577     this->LabelActors[i]->SetScale(s);
    1578     }
     1590    this->SetLabelScale(i, s);
     1591    }
     1592}
     1593
     1594// *********************************************************************
     1595void vtkRpAxisActor::SetLabelScale(int label, const double s)
     1596{
     1597  this->LabelActors[label]->SetScale(s);
    15791598}
    15801599
     
    15961615    return;
    15971616    }
    1598   if (this->Title)
    1599     {
    1600     delete [] this->Title;
    1601     }
     1617  delete [] this->Title;
    16021618  if (t)
    16031619    {
Note: See TracChangeset for help on using the changeset viewer.