Skip to content

Commit

Permalink
ENH: Allow selection of seed points using vtkSeedWidget
Browse files Browse the repository at this point in the history
In several use cases in 3D Slicer we need to be able to select a seed
point, without allowing it to be moved.

Added EnableTranslation (true by default) member to vtkHandleWidget to
allow locking a handle but still process events (to be able to detect when
the user clicks on the handle).

Added seed index to StartInteractionEvent invoked in vtkSeedWidget.
  • Loading branch information
lassoan authored and jcfr committed May 23, 2017
1 parent 93ec100 commit b684733
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Interaction/Widgets/Testing/Cxx/TestSeedWidget.cxx
Expand Up @@ -419,6 +419,14 @@ class vtkSeedCallback : public vtkCommand
std::cout << "Point placed, total of: "
<< this->SeedRepresentation->GetNumberOfSeeds() << std::endl;
}
if (event == vtkCommand::StartInteractionEvent)
{
if (calldata)
{
std::cout << "Start interacting with seed : "
<< *(static_cast< int * >(calldata)) << std::endl;
}
}
if (event == vtkCommand::InteractionEvent)
{
if (calldata)
Expand Down Expand Up @@ -480,6 +488,7 @@ int TestSeedWidget(int argc, char *argv[])
vtkSmartPointer<vtkSeedCallback>::New();
scbk->SeedRepresentation = rep;
widget->AddObserver(vtkCommand::PlacePointEvent,scbk);
widget->AddObserver(vtkCommand::StartInteractionEvent,scbk);
widget->AddObserver(vtkCommand::InteractionEvent,scbk);

// Add the actors to the renderer, set the background and size
Expand Down
6 changes: 6 additions & 0 deletions Interaction/Widgets/vtkHandleWidget.cxx
Expand Up @@ -57,6 +57,7 @@ vtkHandleWidget::vtkHandleWidget()
vtkWidgetEvent::Move,
this, vtkHandleWidget::MoveAction);
this->EnableAxisConstraint = 1;
this->EnableTranslation = 1;
this->AllowHandleResize = 1;
}

Expand Down Expand Up @@ -250,6 +251,11 @@ void vtkHandleWidget::MoveAction(vtkAbstractWidget *w)
return;
}

if (!self->EnableTranslation)
{
return;
}

// Okay, adjust the representation
double eventPosition[2];
eventPosition[0] = static_cast<double>(X);
Expand Down
10 changes: 10 additions & 0 deletions Interaction/Widgets/vtkHandleWidget.h
Expand Up @@ -117,6 +117,15 @@ class VTKINTERACTIONWIDGETS_EXPORT vtkHandleWidget : public vtkAbstractWidget
vtkBooleanMacro( EnableAxisConstraint, int );
//@}

//@{
/**
* Enable moving of handles. By default, the handle can be moved.
*/
vtkSetMacro(EnableTranslation, int);
vtkGetMacro(EnableTranslation, int);
vtkBooleanMacro(EnableTranslation, int);
//@}

//@{
/**
* Allow resizing of handles ? By default the right mouse button scales
Expand Down Expand Up @@ -154,6 +163,7 @@ class VTKINTERACTIONWIDGETS_EXPORT vtkHandleWidget : public vtkAbstractWidget

int WidgetState;
int EnableAxisConstraint;
int EnableTranslation;

// Allow resizing of handles.
int AllowHandleResize;
Expand Down
5 changes: 4 additions & 1 deletion Interaction/Widgets/vtkSeedWidget.cxx
Expand Up @@ -168,7 +168,10 @@ void vtkSeedWidget::AddPointAction(vtkAbstractWidget *w)
// Invoke an event on ourself for the handles
self->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
self->Superclass::StartInteraction();
self->InvokeEvent(vtkCommand::StartInteractionEvent,NULL);
vtkSeedRepresentation *rep = static_cast<
vtkSeedRepresentation * >(self->WidgetRep);
int seedIdx = rep->GetActiveHandle();
self->InvokeEvent(vtkCommand::StartInteractionEvent, &seedIdx);

self->EventCallbackCommand->SetAbortFlag(1);
self->Render();
Expand Down

0 comments on commit b684733

Please sign in to comment.