Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
BUG: WIP: fix vtkPickingManager interaction with widgets
Adds options to explicitly enable and disable vtkAbstractPickers
so that the can be excluded from vtkPickingManager evaluations.

Updates vtkWidgetRepresentation so it can be told by when to
enable and disable any internally managed pickers.

Fixes the one class of pickers used in slicer so that version
4.4 can be released.

WIP: The changes in this commit should be evaluated in terms
of the vtk widget design and possibly picking can be automatically
handled as a byproduct of other calls such that EnablePicking and
DisablePicking are not needed in the public API.

See [1] for more discussion of the problem, along with a python
script that replicates the core issue that caused problem in slicer,
but using pure VTK.

http://na-mic.org/Bug/view.php?id=3808
  • Loading branch information
pieper authored and msmolens committed Jun 28, 2017
1 parent 782d7ed commit 2c55e99
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 6 deletions.
19 changes: 19 additions & 0 deletions Interaction/Widgets/vtkAbstractPolygonalHandleRepresentation3D.cxx
Expand Up @@ -73,6 +73,7 @@ ::vtkAbstractPolygonalHandleRepresentation3D()

// Manage the picking stuff
this->HandlePicker = vtkCellPicker::New();
vtkDebugMacro("making picker " << this->HandlePicker << " in vtkAbstractPolygonalHandleRepresentation3D");
this->HandlePicker->PickFromListOn();
this->HandlePicker->SetTolerance(0.01); //need some fluff

Expand Down Expand Up @@ -125,6 +126,24 @@ void vtkAbstractPolygonalHandleRepresentation3D::RegisterPickers()
->AddPicker(this->HandlePicker, this);
}

//----------------------------------------------------------------------------
void vtkAbstractPolygonalHandleRepresentation3D::UnRegisterPickers()
{
if (this->Renderer &&
this->Renderer->GetRenderWindow() &&
this->Renderer->GetRenderWindow()->GetInteractor())
{
vtkPickingManager* pm = this->Renderer->GetRenderWindow()
->GetInteractor()->GetPickingManager();
if (!pm)
{
return;
}

pm->RemovePicker(this->HandlePicker);
}
}

//----------------------------------------------------------------------
void vtkAbstractPolygonalHandleRepresentation3D::SetHandle( vtkPolyData * pd )
{
Expand Down
Expand Up @@ -201,8 +201,9 @@ class VTKINTERACTIONWIDGETS_EXPORT vtkAbstractPolygonalHandleRepresentation3D
int WaitCount;
int HandleVisibility;

// Register internal Pickers within PickingManager
// Register and Unregister internal Pickers within PickingManager
void RegisterPickers() VTK_OVERRIDE;
virtual void UnRegisterPickers();

// Methods to manipulate the cursor
virtual void Translate(double *p1, double *p2);
Expand Down
12 changes: 12 additions & 0 deletions Interaction/Widgets/vtkOrientedPolygonalHandleRepresentation3D.cxx
Expand Up @@ -41,6 +41,18 @@ vtkOrientedPolygonalHandleRepresentation3D
{
}

//----------------------------------------------------------------------
void vtkOrientedPolygonalHandleRepresentation3D::EnablePicking()
{
this->HandlePicker->SetEnabled(1);
}

//----------------------------------------------------------------------
void vtkOrientedPolygonalHandleRepresentation3D::DisablePicking()
{
this->HandlePicker->SetEnabled(0);
}

//----------------------------------------------------------------------
void vtkOrientedPolygonalHandleRepresentation3D::UpdateHandle()
{
Expand Down
Expand Up @@ -52,6 +52,12 @@ class VTKINTERACTIONWIDGETS_EXPORT vtkOrientedPolygonalHandleRepresentation3D
void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
//@}

// Description:
// Implement the virtual functions to manage internal pickers
// WIP: http://na-mic.org/Bug/view.php?id=3808
virtual void EnablePicking();
virtual void DisablePicking();

protected:
vtkOrientedPolygonalHandleRepresentation3D();
~vtkOrientedPolygonalHandleRepresentation3D() VTK_OVERRIDE;
Expand Down
12 changes: 12 additions & 0 deletions Interaction/Widgets/vtkWidgetRepresentation.h
Expand Up @@ -190,6 +190,18 @@ class VTKINTERACTIONWIDGETS_EXPORT vtkWidgetRepresentation : public vtkProp
int RenderVolumetricGeometry(vtkViewport *vtkNotUsed(viewport)) VTK_OVERRIDE {return 0;}
int HasTranslucentPolygonalGeometry() VTK_OVERRIDE { return 0; }


// WIP: related to http://na-mic.org/Bug/view.php?id=3808
// Since every widget manages it's own internal pickers, they
// need to explicitly enable/disable them so they won't
// interfere with the vtkPickingManager's work
virtual void EnablePicking() {
vtkErrorMacro("Subclass should allow enable/disable picking");
}
virtual void DisablePicking() {
vtkErrorMacro("Subclass should allow enable/disable picking");
}

protected:
vtkWidgetRepresentation();
~vtkWidgetRepresentation() VTK_OVERRIDE;
Expand Down
4 changes: 4 additions & 0 deletions Rendering/Core/vtkAbstractPicker.cxx
Expand Up @@ -34,6 +34,8 @@ vtkAbstractPicker::vtkAbstractPicker()

this->PickFromList = 0;
this->PickList = vtkPropCollection::New();

this->Enabled = 1;
}

vtkAbstractPicker::~vtkAbstractPicker()
Expand Down Expand Up @@ -98,4 +100,6 @@ void vtkAbstractPicker::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "Pick Position: (" << this->PickPosition[0] << ","
<< this->PickPosition[1] << ","
<< this->PickPosition[2] << ")\n";

os << indent << "Enabled: " << this->Enabled << "\n";
}
10 changes: 10 additions & 0 deletions Rendering/Core/vtkAbstractPicker.h
Expand Up @@ -141,6 +141,14 @@ class VTKRENDERINGCORE_EXPORT vtkAbstractPicker : public vtkObject
*/
vtkPropCollection *GetPickList() {return this->PickList;}


// Description:
// Enable or disable picking for this picker (needed for vtkPickingManager)
// WIP: http://na-mic.org/Bug/view.php?id=3808
vtkSetMacro(Enabled,int);
vtkGetMacro(Enabled,int);
vtkBooleanMacro(Enabled,int);

protected:
vtkAbstractPicker();
~vtkAbstractPicker() VTK_OVERRIDE;
Expand All @@ -154,6 +162,8 @@ class VTKRENDERINGCORE_EXPORT vtkAbstractPicker : public vtkObject
// use the following to control picking from a list
int PickFromList;
vtkPropCollection *PickList;

int Enabled;
private:
vtkAbstractPicker(const vtkAbstractPicker&) VTK_DELETE_FUNCTION;
void operator=(const vtkAbstractPicker&) VTK_DELETE_FUNCTION;
Expand Down
33 changes: 28 additions & 5 deletions Rendering/Core/vtkPickingManager.cxx
Expand Up @@ -265,6 +265,7 @@ ComputePickerSelection(double X, double Y, double Z, vtkRenderer* renderer)
double* camPos = renderer->GetActiveCamera()->GetPosition();
double smallestDistance2 = std::numeric_limits<double>::max();

int enabledPickerCount = 0;
for(PickerObjectsType::iterator it = this->Pickers.begin();
it != this->Pickers.end(); ++it)
{
Expand All @@ -273,15 +274,34 @@ ComputePickerSelection(double X, double Y, double Z, vtkRenderer* renderer)

if(pickResult > 0) // Keep closest object picked.
{
double distance2 = vtkMath::Distance2BetweenPoints(camPos, pPos);

if(smallestDistance2 > distance2)
if (it->first->GetEnabled())
{
smallestDistance2 = distance2;
closestPicker = it->first;
enabledPickerCount++;
int pickResult = it->first->Pick(X, Y, Z, renderer);
double* pPos = it->first->GetPickPosition();

if(pickResult > 0) // Keep closest object picked.
{
double distance2 = vtkMath::Distance2BetweenPoints(camPos, pPos);

if(smallestDistance2 > distance2)
{
smallestDistance2 = distance2;
closestPicker = it->first;
}
}
}
}
}
#ifdef NDEBUG
static vtkAbstractPicker* lastPicker = 0;
if (closestPicker != lastPicker)
{
vtkDebugMacro("ComputePickerSelection: "
<< "using picker: " << closestPicker << " of " << enabledPickerCount);
lastPicker = closestPicker;
}
#endif

return closestPicker;
}
Expand Down Expand Up @@ -466,6 +486,7 @@ bool vtkPickingManager::Pick(vtkAbstractPicker* picker, vtkObject* obj)
bool vtkPickingManager::Pick(vtkObject* obj)
{
vtkAbstractPicker* picker = this->Internal->SelectPicker();
std::cerr << "Using picker: " << picker << "\n";
if(!picker)
{
return false;
Expand Down Expand Up @@ -537,6 +558,8 @@ void vtkPickingManager::PrintSelf(ostream& os, vtkIndent indent)
this->Superclass::PrintSelf(os, indent);

os << indent << "RenderWindowInteractor: " << this->Interactor << "\n";
os << indent << "Enabled: " << this->Enabled << "\n";
os << indent << "OptimizeOnInteractorEvents: " << this->OptimizeOnInteractorEvents << "\n";
os << indent << "NumberOfPickers: " << this->Internal->Pickers.size() << "\n";

vtkPickingManager::vtkInternal::PickerObjectsType::iterator it =
Expand Down

0 comments on commit 2c55e99

Please sign in to comment.