Commit 12939a08 authored by David Gobbi's avatar David Gobbi

BUG: Fix the logic for props that are hit more than once - use closest hit.

STYLE: Documentation fixes and improvements.
parent 1547de52
......@@ -36,7 +36,7 @@
#include "vtkBox.h"
#include "vtkImageActor.h"
vtkCxxRevisionMacro(vtkPicker, "1.97");
vtkCxxRevisionMacro(vtkPicker, "1.98");
vtkStandardNewMacro(vtkPicker);
// Construct object with initial tolerance of 1/40th of window. There are no
......@@ -376,28 +376,47 @@ int vtkPicker::Pick(double selectionX, double selectionY, double selectionZ,
bounds[0] -= tol; bounds[1] += tol;
bounds[2] -= tol; bounds[3] += tol;
bounds[4] -= tol; bounds[5] += tol;
if ( vtkBox::IntersectBox(bounds, p1Mapper,
ray, hitPosition, t) )
if ( vtkBox::IntersectBox(bounds, p1Mapper, ray, hitPosition, t) )
{
t = this->IntersectWithLine(p1Mapper, p2Mapper,
tol*0.333*(scale[0]+scale[1]+scale[2]), path,
static_cast<vtkProp3D *>(propCandidate), mapper);
t = this->IntersectWithLine(
p1Mapper, p2Mapper, tol*0.333*(scale[0]+scale[1]+scale[2]),
path, static_cast<vtkProp3D *>(propCandidate), mapper);
if ( t < VTK_DOUBLE_MAX )
{
picked = 1;
if ( ! this->Prop3Ds->IsItemPresent(prop) )
double p[3];
p[0] = (1.0 - t)*p1World[0] + t*p2World[0];
p[1] = (1.0 - t)*p1World[1] + t*p2World[1];
p[2] = (1.0 - t)*p1World[2] + t*p2World[2];
// The IsItemPresent method returns "index+1"
int prevIndex = this->Prop3Ds->IsItemPresent(prop)-1;
if (prevIndex >= 0)
{
this->Prop3Ds->AddItem(static_cast<vtkProp3D *>(prop));
// If already in list, set point to the closest point
double oldp[3];
this->PickedPositions->GetPoint(prevIndex, oldp);
if (vtkMath::Distance2BetweenPoints(p1World, p) <
vtkMath::Distance2BetweenPoints(p1World, oldp))
{
this->PickedPositions->SetPoint(prevIndex, p);
}
}
this->PickedPositions->InsertNextPoint
((1.0 - t)*p1World[0] + t*p2World[0],
(1.0 - t)*p1World[1] + t*p2World[1],
(1.0 - t)*p1World[2] + t*p2World[2]);
// backwards compatibility: also add to this->Actors
if (actor)
else
{
this->Actors->AddItem(actor);
this->Prop3Ds->AddItem(static_cast<vtkProp3D *>(prop));
this->PickedPositions->InsertNextPoint(p);
// backwards compatibility: also add to this->Actors
if (actor)
{
this->Actors->AddItem(actor);
}
}
}
}
......
......@@ -20,17 +20,23 @@
// and a point located from the camera's position.
//
// vtkPicker may return more than one vtkProp3D, since more than one bounding
// box may be intersected. vtkPicker returns the list of props that were hit,
// the pick coordinates in world and untransformed mapper space, and the
// prop (vtkProp3D) and mapper that are "closest" to the camera. The closest
// prop is the one whose center point (i.e., center of bounding box)
// projected on the ray is closest to the camera.
// box may be intersected. vtkPicker returns an unsorted list of props that
// were hit, and a list of the corresponding world points of the hits.
// For the vtkProp3D that is closest to the camera, vtkPicker returns the
// pick coordinates in world and untransformed mapper space, the prop itself,
// the data set, and the mapper. For vtkPicker the closest prop is the one
// whose center point (i.e., center of bounding box) projected on the view
// ray is closest to the camera. Subclasses of vtkPicker use other methods
// for computing the pick point.
// .SECTION See Also
// vtkPicker is used for quick geometric picking. If you desire to pick
// points or cells, use the subclass vtkPointPicker or vtkCellPicker,
// respectively. Or you may use hardware picking to pick any type of vtkProp
// - see vtkPropPicker or vtkWorldPointPicker.
// vtkPicker is used for quick geometric picking. If you desire more precise
// picking of points or cells, use the subclasses vtkPointPicker or
// vtkCellPicker. To do accurate geometric picking of any kind of Prop3D
// (including volumes or images), or if you need both point and and cell
// information together, or if you want to accelerate the pick with locators,
// then use vtkSurfacePicker or vtkVolumePicker. For hardware-accelerated
// picking of any type of vtkProp, use vtkPropPicker or vtkWorldPointPicker.
#ifndef __vtkPicker_h
#define __vtkPicker_h
......@@ -84,9 +90,9 @@ public:
vtkActorCollection *GetActors();
// Description:
// Return a list of the points the the actors returned by GetActors
// Return a list of the points the the actors returned by GetProp3Ds
// were intersected at. The order of this list will match the order of
// GetActors.
// GetProp3Ds.
vtkPoints *GetPickedPositions() {return this->PickedPositions;};
// Description:
......
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