Commit 9aee4360 authored by Cory Quammen's avatar Cory Quammen Committed by Kitware Robot

Merge topic 'distance_representation_scale'

73fd731c Added scale factor for distance representation
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1970
parents 293ed52b 73fd731c
Pipeline #26748 failed with stage
......@@ -944,14 +944,14 @@ int TestDistanceWidget(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
widget->CreateDefaultRepresentation();
widget->SetRepresentation(rep);
VTK_CREATE(vtkDistanceCallback, mcbk);
mcbk->Renderer = ren1;
mcbk->RenderWindow = renWin;
mcbk->Distance = rep;
mcbk->DistanceWidget = widget;
rep->SetScale(0.5);
// Add the actors to the renderer, set the background and size
//
ren1->AddActor(actor);
......@@ -1052,5 +1052,13 @@ int TestDistanceWidget(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
double p2d[3];
rep->GetPoint2DisplayPosition(p2d);
std::cout << "Point 2 Display Position: " << p2d[0] << ", " << p2d[1] << ", " << p2d[2] << std::endl;
rep->SetScale(0.75);
if (rep->GetScale() != 0.75)
{
std::cerr << "Error: GetScale() did not return value set by SetScale()\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
......@@ -38,6 +38,7 @@ vtkDistanceRepresentation::vtkDistanceRepresentation()
this->LabelFormat = new char[8];
sprintf(this->LabelFormat,"%s","%-#6.3g");
this->Scale = 1.0;
this->RulerMode = 0;
this->RulerDistance = 1.0;
this->NumberOfRulerTicks = 5;
......@@ -176,6 +177,7 @@ void vtkDistanceRepresentation::PrintSelf(ostream& os, vtkIndent indent)
os << "(none)\n";
}
os << indent << "Scale: " << this->GetScale() << "\n";
os << indent << "Ruler Mode: "
<< (this->RulerMode ? "On" : "Off") <<"\n";
os << indent << "Ruler Distance: " << this->GetRulerDistance() <<"\n";
......
......@@ -92,6 +92,16 @@ public:
vtkSetStringMacro(LabelFormat);
vtkGetStringMacro(LabelFormat);
// Description:
// Set the scale factor from VTK world coordinates. The ruler marks and label
// will be defined in terms of the scaled space. For example, if the VTK world
// coordinates are assumed to be in inches, but the desired distance units
// should be defined in terms of centimeters, the scale factor should be set
// to 0.3937. The ruler marks will then be spaced in terms of centimeters, and
// the label will contain the measurement in centimeters.
vtkSetMacro(Scale,double);
vtkGetMacro(Scale,double);
// Description:
// Enable or disable ruler mode. When enabled, the ticks on the distance widget
// are separated by the amount specified by RulerDistance. Otherwise, the ivar
......@@ -140,6 +150,10 @@ protected:
// Format for printing the distance
char *LabelFormat;
// Scale to change from the VTK world coordinates to the desired coordinate
// system.
double Scale;
// Ruler related stuff
int RulerMode;
double RulerDistance;
......
......@@ -180,14 +180,19 @@ void vtkDistanceRepresentation2D::BuildRepresentation()
this->Point2Representation->GetWorldPosition(p2);
this->Distance = sqrt(vtkMath::Distance2BetweenPoints(p1,p2));
this->AxisActor->GetPoint1Coordinate()->SetValue(p1);
this->AxisActor->GetPoint1Coordinate()->SetValue(p1);
this->AxisActor->GetPoint2Coordinate()->SetValue(p2);
this->AxisActor->SetRulerMode(this->RulerMode);
this->AxisActor->SetRulerDistance(this->RulerDistance);
this->AxisActor->SetRulerDistance(this->RulerDistance * this->Scale);
this->AxisActor->SetNumberOfLabels(this->NumberOfRulerTicks);
double scaledDistance = this->Distance;
if (this->Scale != 0.0)
{
scaledDistance /= this->Scale;
}
char string[512];
sprintf(string, this->LabelFormat, this->Distance);
sprintf(string, this->LabelFormat, scaledDistance);
this->AxisActor->SetTitle(string);
this->BuildTime.Modified();
......@@ -210,14 +215,14 @@ int vtkDistanceRepresentation2D::RenderOverlay(vtkViewport *v)
return this->AxisActor->RenderOverlay(v);
}
else
{
return 0;
}
}
//----------------------------------------------------------------------
int vtkDistanceRepresentation2D::RenderOpaqueGeometry(vtkViewport *v)
{
{
return 0;
}
}
//----------------------------------------------------------------------
int vtkDistanceRepresentation2D::RenderOpaqueGeometry(vtkViewport *v)
{
this->BuildRepresentation();
if ( this->AxisActor->GetVisibility() )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment