Skip to content
Snippets Groups Projects
Commit 95831ace authored by Joachim Pouderoux's avatar Joachim Pouderoux Committed by Kitware Robot
Browse files

Merge topic 'EnhanceCylinderWidget'


73999adf Add modifier to translate center of the cylinder along the cylinder axis.

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarMathieu Westphal <mathieu.westphal@kitware.com>
Merge-request: !1179
parents fc131831 73999adf
No related branches found
No related tags found
No related merge requests found
......@@ -383,6 +383,10 @@ void vtkImplicitCylinderRepresentation::SetRepresentationState(int state)
this->HighlightCylinder(1);
this->HighlightOutline(1);
}
else if ( state == vtkImplicitCylinderRepresentation::TranslatingCenter )
{
this->HighlightNormal(1);
}
else
{
this->HighlightNormal(0);
......@@ -436,6 +440,10 @@ void vtkImplicitCylinderRepresentation::WidgetInteraction(double e[2])
{
this->TranslateCenter(prevPickPoint, pickPoint);
}
else if ( this->InteractionState == vtkImplicitCylinderRepresentation::TranslatingCenter )
{
this->TranslateCenterOnAxis(prevPickPoint, pickPoint);
}
else if ( this->InteractionState == vtkImplicitCylinderRepresentation::AdjustingRadius )
{
this->AdjustRadius(e[0], e[1], prevPickPoint, pickPoint);
......@@ -681,6 +689,9 @@ void vtkImplicitCylinderRepresentation::PrintSelf(ostream& os, vtkIndent indent)
case Scaling:
os << "Scaling\n";
break;
case TranslatingCenter:
os << "TranslatingCenter\n";
break;
}
// this->InteractionState is printed in superclass
......@@ -828,6 +839,47 @@ void vtkImplicitCylinderRepresentation::TranslateCenter(double *p1, double *p2)
this->BuildRepresentation();
}
//----------------------------------------------------------------------------
// Translate the center on the axis
void vtkImplicitCylinderRepresentation::TranslateCenterOnAxis(double *p1, double *p2)
{
// Get the motion vector
double v[3];
v[0] = p2[0] - p1[0];
v[1] = p2[1] - p1[1];
v[2] = p2[2] - p1[2];
// Add to the current point, project back down onto plane
double *c = this->Cylinder->GetCenter();
double *a = this->Cylinder->GetAxis();
double newCenter[3];
newCenter[0] = c[0] + v[0];
newCenter[1] = c[1] + v[1];
newCenter[2] = c[2] + v[2];
// Normalize the axis vector
const double imag = 1. /
std::max(1.0e-100, sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]));
double an[3];
an[0] = a[0] * imag;
an[1] = a[1] * imag;
an[2] = a[2] * imag;
// Project the point on the axis vector
double u[3];
u[0] = newCenter[0] - c[0];
u[1] = newCenter[1] - c[1];
u[2] = newCenter[2] - c[2];
double dot = an[0] * u[0] + an[1] * u[1] + an[2] * u[2];
newCenter[0] = c[0] + an[0] * dot;
newCenter[1] = c[1] + an[1] * dot;
newCenter[2] = c[2] + an[2] * dot;
this->SetCenter(newCenter[0],newCenter[1],newCenter[2]);
this->BuildRepresentation();
}
//----------------------------------------------------------------------------
void vtkImplicitCylinderRepresentation::Scale(double *p1, double *p2,
double vtkNotUsed(X), double Y)
......
......@@ -258,7 +258,8 @@ public:
MovingCenter,
RotatingAxis,
AdjustingRadius,
Scaling
Scaling,
TranslatingCenter
};
// Description:
......@@ -269,7 +270,7 @@ public:
// ComputeInteractionState() is invoked that returns a state based on
// geometric considerations (i.e., cursor near a widget feature), then
// based on events, the widget may modify this further.
vtkSetClampMacro(InteractionState,int,Outside,Scaling);
vtkSetClampMacro(InteractionState,int,Outside,TranslatingCenter);
// Description:
// Sets the visual appearance of the representation based on the
......@@ -370,6 +371,7 @@ protected:
void TranslateCylinder(double *p1, double *p2);
void TranslateOutline(double *p1, double *p2);
void TranslateCenter(double *p1, double *p2);
void TranslateCenterOnAxis(double *p1, double *p2);
void ScaleRadius(double *p1, double *p2);
void AdjustRadius(double X, double Y, double *p1, double *p2);
void Scale(double *p1, double *p2, double X, double Y);
......
......@@ -124,6 +124,13 @@ void vtkImplicitCylinderWidget::SelectAction(vtkAbstractWidget *w)
return;
}
if (self->Interactor->GetControlKey() &&
interactionState == vtkImplicitCylinderRepresentation::MovingCenter)
{
reinterpret_cast<vtkImplicitCylinderRepresentation*>(self->WidgetRep)->
SetInteractionState(vtkImplicitCylinderRepresentation::TranslatingCenter);
}
// We are definitely selected
self->GrabFocus(self->EventCallbackCommand);
double eventPos[2];
......
......@@ -36,7 +36,8 @@
// If the center point (handle) is selected:
// LeftButtonPressEvent - select handle (if on slider)
// LeftButtonReleaseEvent - release handle (if selected)
// MouseMoveEvent - move the center point (constrained to plane)
// MouseMoveEvent - move the center point (constrained to plane or on the
// axis if CTRL key is pressed)
// If the cylinder is selected:
// LeftButtonPressEvent - select cylinder
// LeftButtonReleaseEvent - release cylinder
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment