------------------------------------------------------------------------------ Determine and set scale factor and position for labels. ------------------------------------------------------------------------------
| 468 | // Determine and set scale factor and position for labels. |
| 469 | //------------------------------------------------------------------------------ |
| 470 | void vtkAxisActor::SetLabelPositions(vtkViewport* viewport, bool force) |
| 471 | { |
| 472 | if (!force && (!this->LabelVisibility || this->NumberOfLabelsBuilt == 0)) |
| 473 | { |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | // |
| 478 | // xadjust & yadjust are used for positioning the label correctly |
| 479 | // depending upon the 'orientation' of the axis as determined |
| 480 | // by its position in view space (via transformed bounds). |
| 481 | // |
| 482 | double displayBounds[6] = { 0., 0., 0., 0., 0., 0. }; |
| 483 | this->TransformBounds(viewport, displayBounds); |
| 484 | |
| 485 | double bounds[6], tickBottom[3], tickTop[3], pos[3]; |
| 486 | double labelAngle = vtkMath::RadiansFromDegrees(this->LabelTextProperty->GetOrientation()); |
| 487 | double labelCos = fabs(cos(labelAngle)); |
| 488 | double labelSin = fabs(sin(labelAngle)); |
| 489 | vtkAxisFollower* pAxisFollower = nullptr; |
| 490 | |
| 491 | for (int i = 0, ptIdx = 0; |
| 492 | i < this->NumberOfLabelsBuilt && ((ptIdx + 1) < this->MajorTickPts->GetNumberOfPoints()); |
| 493 | i++, ptIdx += 4) |
| 494 | { |
| 495 | this->MajorTickPts->GetPoint(ptIdx, tickTop); |
| 496 | this->MajorTickPts->GetPoint(ptIdx + 1, tickBottom); |
| 497 | |
| 498 | pAxisFollower = this->LabelProps[i]->GetFollower(); |
| 499 | |
| 500 | // get Label actor Transform matrix |
| 501 | vtkRenderer* ren = vtkRenderer::SafeDownCast(viewport); |
| 502 | if (ren) |
| 503 | { |
| 504 | pAxisFollower->ComputeTransformMatrix(ren); |
| 505 | } |
| 506 | |
| 507 | // WARNING: calling GetBounds() before ComputeTransformMatrix(), prevent this->Transform to be |
| 508 | // updated |
| 509 | |
| 510 | // previous version: this->LabelActors[i]->GetMapper()->GetBounds(bounds); didn't include scale |
| 511 | // labels |
| 512 | // vtkProp3D::GetBounds() include previous transform (scale, orientation, translation) |
| 513 | pAxisFollower->GetBounds(bounds); |
| 514 | double labelWidth = (bounds[1] - bounds[0]); |
| 515 | double labelHeight = (bounds[3] - bounds[2]); |
| 516 | double labelMagnitude = sqrt(labelWidth * labelWidth + labelHeight * labelHeight); |
| 517 | |
| 518 | if (this->TickVisibility) |
| 519 | { |
| 520 | pos[0] = tickBottom[0]; |
| 521 | pos[1] = tickBottom[1]; |
| 522 | pos[2] = tickBottom[2]; |
| 523 | } |
| 524 | else |
| 525 | { |
| 526 | pos[0] = (tickTop[0] + tickBottom[0]) / 2; |
| 527 | pos[1] = (tickTop[1] + tickBottom[1]) / 2; |
no test coverage detected