Commit 264145fb authored by Will Schroeder's avatar Will Schroeder
Browse files

ENH:Added GetAngle() method to vtkAngleRepresentation

parent 18b05a53
......@@ -25,7 +25,7 @@
#include "vtkObjectFactory.h"
#include "vtkMath.h"
vtkCxxRevisionMacro(vtkLeaderActor2D, "1.4");
vtkCxxRevisionMacro(vtkLeaderActor2D, "1.5");
vtkStandardNewMacro(vtkLeaderActor2D);
vtkCxxSetObjectMacro(vtkLeaderActor2D,LabelTextProperty,vtkTextProperty);
......@@ -43,6 +43,8 @@ vtkLeaderActor2D::vtkLeaderActor2D()
this->Position2Coordinate->SetReferenceCoordinate(NULL);
this->Radius = 0.0;
this->Length = 0.0;
this->Angle = 0.0;
this->Label = NULL;
this->LabelFactor = 1.0;
......@@ -221,15 +223,17 @@ void vtkLeaderActor2D::BuildLeader(vtkViewport *viewport)
// Build the labels
int i, clippedLeader=0;
double xL[3], xR[3], c1[3], c2[3];
double *x1 = this->PositionCoordinate->GetComputedWorldValue(viewport);
double *x2 = this->Position2Coordinate->GetComputedWorldValue(viewport);
this->Length = sqrt(vtkMath::Distance2BetweenPoints(x1,x2));
if ( this->AutoLabel || (this->Label != NULL && this->Label[0] != 0) )
{
int stringSize[2];
if ( this->AutoLabel )
{
char string[512];
double *x1 = this->PositionCoordinate->GetComputedWorldValue(viewport);
double *x2 = this->Position2Coordinate->GetComputedWorldValue(viewport);
sprintf(string, this->LabelFormat, sqrt(vtkMath::Distance2BetweenPoints(x1,x2)));
sprintf(string, this->LabelFormat, this->Length);
this->LabelMapper->SetInput(string);
}
else
......@@ -533,13 +537,14 @@ void vtkLeaderActor2D::BuildCurvedLeader(double p1[3], double p2[3], double ray[
}
// Now insert lines. Only those not clipped by the string are added.
this->Angle = (theta1-theta2)*vtkMath::RadiansToDegrees();
if ( this->AutoLabel || (this->Label != NULL && this->Label[0] != 0) )
{
int stringSize[2];
if ( this->AutoLabel )
{
char string[512];
sprintf(string, this->LabelFormat, (theta1-theta2)*vtkMath::RadiansToDegrees());
sprintf(string, this->LabelFormat, this->Angle);
this->LabelMapper->SetInput(string);
}
else
......
......@@ -147,6 +147,12 @@ public:
vtkSetStringMacro(LabelFormat);
vtkGetStringMacro(LabelFormat);
// Description:
// Obtain the length of the leader if the leader is not curved,
// otherwise obtain the angle that the leader circumscribes.
vtkGetMacro(Length,double);
vtkGetMacro(Angle,double);
// Description:
// Methods required by vtkProp and vtkActor2D superclasses.
int RenderOverlay(vtkViewport* viewport);
......@@ -169,7 +175,11 @@ protected:
double theta, vtkViewport *viewport, int viewportChanged);
int InStringBox(double center[3], int stringSize[2], double x[3]);
// Characteristics of the leader
double Radius;
double Length;
double Angle;
int AutoLabel;
char *LabelFormat;
......
......@@ -42,10 +42,19 @@ class vtkAngleCallback : public vtkCommand
public:
static vtkAngleCallback *New()
{ return new vtkAngleCallback; }
virtual void Execute(vtkObject*, unsigned long, void*)
virtual void Execute(vtkObject*, unsigned long eid, void*)
{
cout << "point placed\n";
if ( eid == vtkCommand::PlacePointEvent )
{
cout << "point placed\n";
}
else //if ( eid == vtkCommand::InteractionEvent )
{
cout << "Angle: " << this->Rep->GetAngle() << "\n";
}
}
vtkAngleRepresentation2D *Rep;
vtkAngleCallback():Rep(0) {}
};
......@@ -80,7 +89,9 @@ int TestAngleWidget( int argc, char *argv[] )
widget->SetRepresentation(rep);
vtkAngleCallback *mcbk = vtkAngleCallback::New();
mcbk->Rep = rep;
widget->AddObserver(vtkCommand::PlacePointEvent,mcbk);
// widget->AddObserver(vtkCommand::InteractionEvent,mcbk);
// Add the actors to the renderer, set the background and size
//
......
......@@ -24,7 +24,7 @@
#include "vtkMath.h"
#include "vtkTextProperty.h"
vtkCxxRevisionMacro(vtkAngleRepresentation, "1.2");
vtkCxxRevisionMacro(vtkAngleRepresentation, "1.3");
vtkCxxSetObjectMacro(vtkAngleRepresentation,HandleRepresentation,vtkHandleRepresentation);
......@@ -178,6 +178,7 @@ void vtkAngleRepresentation::PrintSelf(ostream& os, vtkIndent indent)
//Superclass typedef defined in vtkTypeMacro() found in vtkSetGet.h
this->Superclass::PrintSelf(os,indent);
os << indent << "Angle: " << this->GetAngle() << "\n";
os << indent << "Tolerance: " << this->Tolerance <<"\n";
os << indent << "Ray1 Visibility: " << (this->Ray1Visibility ? "On\n" : "Off\n");
os << indent << "Ray2 Visibility: " << (this->Ray2Visibility ? "On\n" : "Off\n");
......
......@@ -41,6 +41,11 @@ public:
vtkTypeRevisionMacro(vtkAngleRepresentation,vtkWidgetRepresentation);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// This representation and all subclasses must keep an angle (in degrees)
// consistent with the state of the widget.
virtual double GetAngle() = 0;
// Description:
// Methods to Set/Get the coordinates of the three points defining
// this representation. Note that methods are available for both
......
......@@ -21,7 +21,7 @@
#include "vtkInteractorObserver.h"
#include "vtkMath.h"
vtkCxxRevisionMacro(vtkAngleRepresentation2D, "1.2");
vtkCxxRevisionMacro(vtkAngleRepresentation2D, "1.3");
vtkStandardNewMacro(vtkAngleRepresentation2D);
......@@ -56,6 +56,12 @@ vtkAngleRepresentation2D::~vtkAngleRepresentation2D()
this->Arc->Delete();
}
//----------------------------------------------------------------------
double vtkAngleRepresentation2D::GetAngle()
{
return this->Arc->GetAngle();
}
//----------------------------------------------------------------------
void vtkAngleRepresentation2D::GetPoint1WorldPosition(double pos[3])
{
......
......@@ -47,6 +47,10 @@ public:
vtkTypeRevisionMacro(vtkAngleRepresentation2D,vtkAngleRepresentation);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Satisfy the superclasses API.
virtual double GetAngle();
// Description:
// Methods to Set/Get the coordinates of the two points defining
// this representation. Note that methods are available for both
......
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