Changeset 5802 for vtkvis/trunk/vtkRpAxisActor.cpp
- Timestamp:
- Aug 9, 2015, 3:59:03 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vtkvis/trunk/vtkRpAxisActor.cpp
r3549 r5802 2 2 3 3 Program: Visualization Toolkit 4 Module: vtkRpAxisActor.c pp4 Module: vtkRpAxisActor.cxx 5 5 Thanks: Kathleen Bonnell, B Division, Lawrence Livermore Nat'l Laboratory 6 6 … … 32 32 #include "vtkVectorText.h" 33 33 #include "vtkViewport.h" 34 #include "vtkVersion.h" 35 #include "vtkWindow.h" 34 36 35 37 vtkStandardNewMacro(vtkRpAxisActor); … … 60 62 this->Range[0] = 0.0; 61 63 this->Range[1] = 1.0; 64 this->ScreenSize = 10.; 65 this->LabelOffset = 20.; 66 this->TitleOffset = 20.; 62 67 63 68 this->Bounds[0] = this->Bounds[2] = this->Bounds[4] = -1; … … 70 75 this->TitleTextProperty->SetColor(0.,0.,0.); 71 76 this->TitleTextProperty->SetFontFamilyToArial(); 72 this->TitleTextProperty->SetFontSize(14); 77 this->TitleTextProperty->SetFontSize(18); 78 this->TitleTextProperty->SetVerticalJustificationToCentered(); 79 this->TitleTextProperty->SetJustificationToCentered(); 73 80 74 81 this->TitleVector = vtkVectorText::New(); … … 77 84 this->TitleVector->GetOutputPort()); 78 85 this->TitleActor = vtkRpAxisFollower::New(); 86 this->TitleActor->SetAxis(this); 79 87 this->TitleActor->SetMapper(this->TitleMapper); 80 88 this->TitleActor->SetEnableDistanceLOD(0); … … 90 98 this->LabelTextProperty->SetColor(0.,0.,0.); 91 99 this->LabelTextProperty->SetFontFamilyToArial(); 92 this->LabelTextProperty->SetFontSize(12); 100 this->LabelTextProperty->SetFontSize(14); 101 this->LabelTextProperty->SetVerticalJustificationToBottom(); 102 this->LabelTextProperty->SetJustificationToLeft(); 93 103 94 104 this->AxisLines = vtkPolyData::New(); … … 177 187 this->CalculateLabelOffset = 1; 178 188 179 this->ScreenSize = 10.;180 181 189 // Instance variables specific to 2D mode 182 190 this->Use2DMode = 0; … … 221 229 } 222 230 223 if (this->LabelFormat) 224 { 225 delete [] this->LabelFormat; 226 this->LabelFormat = NULL; 227 } 231 delete [] this->LabelFormat; 232 this->LabelFormat = NULL; 228 233 229 234 if (this->TitleVector) … … 248 253 } 249 254 250 if (this->Title) 251 { 252 delete [] this->Title; 253 this->Title = NULL; 254 } 255 delete [] this->Title; 256 this->Title = NULL; 255 257 256 258 if (this->TitleTextProperty) … … 410 412 if (this->Title != NULL && this->Title[0] != 0 && this->TitleVisibility) 411 413 { 412 if (this->Use2DMode == 0) 414 if (this->Use2DMode) 415 { 416 renderedSomething += this->TitleActor2D->RenderOpaqueGeometry(viewport); 417 } 418 else 413 419 { 414 420 renderedSomething += this->TitleActor->RenderOpaqueGeometry(viewport); 415 421 } 416 else417 {418 renderedSomething += this->TitleActor2D->RenderOpaqueGeometry(viewport);419 }420 422 } 421 423 if (this->AxisVisibility || this->TickVisibility) … … 435 437 for (i=0; i<this->NumberOfLabelsBuilt; i++) 436 438 { 437 if (this->Use2DMode == 0) 439 if (this->Use2DMode) 440 { 441 renderedSomething += 442 this->LabelActors2D[i]->RenderOpaqueGeometry(viewport); 443 } 444 else 438 445 { 439 446 renderedSomething += 440 447 this->LabelActors[i]->RenderOpaqueGeometry(viewport); 441 448 } 442 else443 {444 renderedSomething +=445 this->LabelActors2D[i]->RenderOpaqueGeometry(viewport);446 }447 449 } 448 450 } … … 478 480 renderedSomething += this->GridpolysActor->RenderTranslucentPolygonalGeometry(viewport); 479 481 } 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 } 482 510 return renderedSomething; 483 511 } … … 493 521 if (!this->AxisHasZeroLength && !this->DrawGridlinesOnly) 494 522 { 495 if ( this->Use2DMode == 1)523 if (this->Use2DMode) 496 524 { 497 525 renderedSomething += this->TitleActor2D->RenderOverlay(viewport); 526 } 527 else 528 { 529 renderedSomething += this->TitleActor->RenderOverlay(viewport); 498 530 } 499 531 if (this->LabelVisibility) … … 501 533 for (i=0; i<this->NumberOfLabelsBuilt; i++) 502 534 { 503 if (this->Use2DMode == 1)535 if (this->Use2DMode) 504 536 { 505 537 renderedSomething += this->LabelActors2D[i]->RenderOverlay(viewport); 538 } 539 else 540 { 541 renderedSomething += this->LabelActors[i]->RenderOverlay(viewport); 506 542 } 507 543 } … … 578 614 579 615 if (this->DrawGridpolys && 580 this- GridpolysActor->HasTranslucentPolygonalGeometry())616 this->GridpolysActor->HasTranslucentPolygonalGeometry()) 581 617 { 582 618 return 1; … … 627 663 this->TitleActor->SetProperty(this->GetProperty()); 628 664 this->TitleActor->GetProperty()->SetColor(this->TitleTextProperty->GetColor()); 665 this->TitleActor->GetProperty()->SetOpacity(this->TitleTextProperty->GetOpacity()); 629 666 } 630 667 … … 660 697 } 661 698 662 // If label positions changed, need to rescale663 this->AutoScale(viewport);664 665 699 this->LastAxisPosition = this->AxisPosition; 666 700 … … 686 720 this->LabelActors[i]->SetProperty(this->GetProperty()); 687 721 this->LabelActors[i]->GetProperty()->SetColor(this->LabelTextProperty->GetColor()); 722 this->LabelActors[i]->GetProperty()->SetOpacity(this->LabelTextProperty->GetOpacity()); 688 723 this->LabelActors[i]->SetOrientation(0., 0., this->LabelTextProperty->GetOrientation()); 689 724 … … 703 738 } 704 739 705 int vtkRpAxisActorMultiplierTable1[4] = { -1, -1, 1, 1};706 int vtkRpAxisActorMultiplierTable2[4] = { -1, 1, 1, -1};740 static const int vtkRpAxisActorMultiplierTable1[4] = { -1, -1, 1, 1}; 741 static const int vtkRpAxisActorMultiplierTable2[4] = { -1, 1, 1, -1}; 707 742 708 743 // ******************************************************************* … … 716 751 } 717 752 718 double bounds[6], center[3], tick[3], pos[3] , scale[3];753 double bounds[6], center[3], tick[3], pos[3]; 719 754 int i = 0; 720 755 int xmult = 0; 721 756 int ymult = 0; 757 double labelAngle = vtkMath::RadiansFromDegrees(this->LabelTextProperty->GetOrientation()); 758 double labelCos = fabs(cos(labelAngle)); 759 double labelSin = fabs(sin(labelAngle)); 760 722 761 723 762 switch (this->AxisType) … … 755 794 756 795 this->LabelActors[i]->GetMapper()->GetBounds(bounds); 757 this->LabelActors[i]->GetScale(scale);758 796 759 797 if(this->CalculateLabelOffset) 760 798 { 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); 763 801 764 802 center[0] = tick[0] + xmult * (halfWidth + this->MinorTickSize); … … 772 810 else 773 811 { 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); 781 818 } 782 819 783 820 this->LabelActors[i]->SetPosition(pos[0], pos[1], pos[2]); 784 821 } 785 }786 787 void788 vtkRpAxisActor::AutoScale(vtkViewport *viewport)789 {790 double newTitleScale791 = 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 newLabelScale803 = this->AutoScale(viewport,804 this->ScreenSize,805 labelActors[j]->GetPosition());806 807 labelActors[j]->SetScale(newLabelScale);808 }809 }810 811 double812 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 * screenSize819 * 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;829 822 } 830 823 … … 841 834 { 842 835 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); 847 838 } 848 839 … … 906 897 return; 907 898 } 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 909 908 for (int i = 0; i < this->NumberOfLabelsBuilt; i++) 910 909 { … … 923 922 int bbox[4]; 924 923 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 925 928 this->LabelActors2D[i]->GetInput(), bbox)) 929 #endif 926 930 { 927 931 vtkErrorMacro(<< "Unable to calculate bounding box for label " … … 951 955 return; 952 956 } 953 double labBounds[6], titleBounds[6], center[3], pos[3] , scale[3];957 double labBounds[6], titleBounds[6], center[3], pos[3]; 954 958 double labHeight, maxHeight = 0, labWidth, maxWidth = 0; 955 959 double halfTitleWidth, halfTitleHeight; 960 double labelAngle = vtkMath::RadiansFromDegrees(this->LabelTextProperty->GetOrientation()); 961 double labelCos = fabs(cos(labelAngle)); 962 double labelSin = fabs(sin(labelAngle)); 956 963 957 964 double *p1 = this->Point1Coordinate->GetValue(); … … 991 998 { 992 999 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; 995 1001 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; 997 1003 maxHeight = (labHeight > maxHeight ? labHeight : maxHeight); 998 1004 } … … 1002 1008 this->TitleActor->GetProperty()->SetColor(this->TitleTextProperty->GetColor()); 1003 1009 this->TitleActor->SetCamera(this->Camera); 1004 this->TitleActor->SetPosition(p2[0], p2[1], p2[2]);1005 1010 this->TitleActor->GetMapper()->GetBounds(titleBounds); 1006 this->TitleActor->GetScale(scale); 1011 1007 1012 if(!this->GetCalculateTitleOffset()) 1008 1013 { … … 1014 1019 center[2] = p1[2] + (p2[2] - p1[2]) / 2.0; 1015 1020 1021 halfTitleHeight = (titleBounds[3] - titleBounds[2]) * 0.5; 1016 1022 if(this->CalculateTitleOffset) 1017 1023 { 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; 1020 1025 center[0] += xmult * (halfTitleWidth + maxWidth); 1021 1026 center[1] += ymult * (halfTitleHeight + 2*maxHeight); 1027 } 1028 else 1029 { 1030 this->TitleActor->SetScreenOffset(this->TitleOffset + 1031 this->LabelOffset + this->ScreenSize * (maxHeight + halfTitleHeight)); 1022 1032 } 1023 1033 … … 1044 1054 this->TitleActor2D->SetInput( this->TitleVector->GetText() ); 1045 1055 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); 1050 1058 1051 1059 if (this->AxisType == VTK_AXIS_TYPE_Y) … … 1273 1281 // 1274 1282 int i, numLabels = labels->GetNumberOfValues(); 1283 if (numLabels < 0) 1284 { 1285 vtkErrorMacro(<< "Number of labels " << numLabels << " is invalid"); 1286 return; 1287 } 1275 1288 if (this->NumberOfLabelsBuilt != numLabels) 1276 1289 { … … 1302 1315 this->LabelVectors[i]->GetOutputPort()); 1303 1316 this->LabelActors[i] = vtkRpAxisFollower::New(); 1317 this->LabelActors[i]->SetAxis(this); 1304 1318 this->LabelActors[i]->SetMapper(this->LabelMappers[i]); 1305 1319 this->LabelActors[i]->SetEnableDistanceLOD(0); … … 1307 1321 this->LabelActors[i]->GetProperty()->SetDiffuse(0.); 1308 1322 this->LabelActors[i]->GetProperty()->SetColor(this->LabelTextProperty->GetColor()); 1323 this->LabelActors[i]->GetProperty()->SetOpacity(this->LabelTextProperty->GetOpacity()); 1309 1324 this->LabelActors2D[i] = vtkTextActor::New(); 1310 1325 } … … 1461 1476 // ********************************************************************* 1462 1477 void 1463 vtkRpAxisActor::SetBounds( double b[6])1478 vtkRpAxisActor::SetBounds(const double b[6]) 1464 1479 { 1465 1480 if ((this->Bounds[0] != b[0]) || … … 1537 1552 this->LabelActors[i]->SetProperty(newProp); 1538 1553 this->LabelActors[i]->GetMapper()->GetBounds(bounds); 1539 this->LabelActors[i]->GetProperty()->SetColor(this->LabelTextProperty->GetColor());1540 1554 xsize = bounds[1] - bounds[0]; 1541 1555 ysize = bounds[3] - bounds[2]; … … 1562 1576 newProp->Delete(); 1563 1577 this->TitleActor->GetMapper()->GetBounds(bounds); 1564 this->TitleActor->GetProperty()->SetColor(this->TitleTextProperty->GetColor());1565 1578 xsize = bounds[1] - bounds[0]; 1566 1579 ysize = bounds[3] - bounds[2]; … … 1575 1588 for (int i=0; i < this->NumberOfLabelsBuilt; i++) 1576 1589 { 1577 this->LabelActors[i]->SetScale(s); 1578 } 1590 this->SetLabelScale(i, s); 1591 } 1592 } 1593 1594 // ********************************************************************* 1595 void vtkRpAxisActor::SetLabelScale(int label, const double s) 1596 { 1597 this->LabelActors[label]->SetScale(s); 1579 1598 } 1580 1599 … … 1596 1615 return; 1597 1616 } 1598 if (this->Title) 1599 { 1600 delete [] this->Title; 1601 } 1617 delete [] this->Title; 1602 1618 if (t) 1603 1619 {
Note: See TracChangeset
for help on using the changeset viewer.