------------------------------------------------------------------------------
| 707 | |
| 708 | //------------------------------------------------------------------------------ |
| 709 | void vtkLineRepresentation::BuildRepresentation() |
| 710 | { |
| 711 | // Rebuild only if necessary |
| 712 | if (this->GetMTime() > this->BuildTime || |
| 713 | this->Point1Representation->GetMTime() > this->BuildTime || |
| 714 | this->Point2Representation->GetMTime() > this->BuildTime || |
| 715 | this->LineHandleRepresentation->GetMTime() > this->BuildTime || |
| 716 | (this->Renderer && this->Renderer->GetVTKWindow() && |
| 717 | (this->Renderer->GetVTKWindow()->GetMTime() > this->BuildTime || |
| 718 | this->Renderer->GetActiveCamera()->GetMTime() > this->BuildTime))) |
| 719 | { |
| 720 | this->UpdatePointAndLineProperties(); |
| 721 | if (!this->InitializedDisplayPosition && this->Renderer) |
| 722 | { |
| 723 | this->SetPoint1WorldPosition(this->LineSource->GetPoint1()); |
| 724 | this->SetPoint2WorldPosition(this->LineSource->GetPoint2()); |
| 725 | this->ValidPick = 1; |
| 726 | this->InitializedDisplayPosition = 1; |
| 727 | } |
| 728 | |
| 729 | // Make sure that tolerance is consistent between handles and this representation |
| 730 | this->Point1Representation->SetTolerance(this->Tolerance); |
| 731 | this->Point2Representation->SetTolerance(this->Tolerance); |
| 732 | this->LineHandleRepresentation->SetTolerance(this->Tolerance); |
| 733 | |
| 734 | // Retrieve end point information |
| 735 | double x1[3], x2[3]; |
| 736 | this->GetPoint1WorldPosition(x1); |
| 737 | |
| 738 | this->LineSource->SetPoint1(x1); |
| 739 | static_cast<vtkSphereSource*>(this->HandleGeometry[0])->SetCenter(x1); |
| 740 | |
| 741 | this->GetPoint2WorldPosition(x2); |
| 742 | this->LineSource->SetPoint2(x2); |
| 743 | if (this->DirectionalLine) |
| 744 | { |
| 745 | static_cast<vtkConeSource*>(this->HandleGeometry[1])->SetCenter(x2); |
| 746 | vtkVector3d dir(x2); |
| 747 | dir = dir - vtkVector3d(x1); |
| 748 | static_cast<vtkConeSource*>(this->HandleGeometry[1])->SetDirection(dir.GetData()); |
| 749 | } |
| 750 | else |
| 751 | { |
| 752 | static_cast<vtkSphereSource*>(this->HandleGeometry[1])->SetCenter(x2); |
| 753 | } |
| 754 | |
| 755 | this->Distance = sqrt(vtkMath::Distance2BetweenPoints(x1, x2)); |
| 756 | |
| 757 | // Place the DistanceAnnotation right in between the two points. |
| 758 | double x[3] = { (x1[0] + x2[0]) / 2.0, (x1[1] + x2[1]) / 2.0, (x1[2] + x2[2]) / 2.0 }; |
| 759 | std::string distanceAnnotationFormat = |
| 760 | this->DistanceAnnotationFormat ? vtk::to_std_format(this->DistanceAnnotationFormat) : ""; |
| 761 | std::string string; |
| 762 | VTK_FORMAT_IF_ERROR_RETURN(string = vtk::format(distanceAnnotationFormat, this->Distance), ); |
| 763 | this->TextInput->SetText(string.c_str()); |
| 764 | this->TextActor->SetPosition(x); |
| 765 | if (this->Renderer) |
| 766 | { |
no test coverage detected