Commit 808ce79e authored by Ken Martin's avatar Ken Martin

deprecate OpenVRPropPicker as it is not needed

The two main methods now work without OpenVR and are
moved into PropPicker where they should be.
parent 4122f725
......@@ -16,9 +16,13 @@
#include "vtkAssemblyNode.h"
#include "vtkAssemblyPath.h"
#include "vtkBox.h"
#include "vtkCamera.h"
#include "vtkCommand.h"
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
#include "vtkTransform.h"
#include "vtkWorldPointPicker.h"
vtkStandardNewMacro(vtkPropPicker);
......@@ -198,6 +202,154 @@ int vtkPropPicker::PickProp3DPoint(double pos[3], vtkRenderer *renderer)
}
}
// Pick from the given collection
int vtkPropPicker::Pick3DRay(double pos[3], double wori[4], vtkRenderer *renderer)
{
//Compute event orientation
if (this->PickFromList)
{
return this->PickProp3DRay(pos, wori, renderer,
this->PickList);
}
else
{
return this->PickProp3DRay(pos, wori, renderer,
renderer->GetViewProps());
}
}
// Pick from the given collection
int vtkPropPicker::PickProp3DRay(
double selectionPt[3], double wori[4],
vtkRenderer *renderer, vtkPropCollection* propCollection)
{
// Initialize picking process
this->Initialize();
this->Renderer = renderer;
// Invoke start pick method if defined
this->InvokeEvent(vtkCommand::StartPickEvent, nullptr);
//Event position - Ray start position
double p0[4];
p0[0] = selectionPt[0];
p0[1] = selectionPt[1];
p0[2] = selectionPt[2];
p0[3] = 1.0;
//Compute ray direction
vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
trans->RotateWXYZ(wori[0], wori[1], wori[2], wori[3]);
double* rayDirection = trans->TransformDoubleVector(0.0, 0.0, -1.0);
vtkCamera* cam = renderer->GetActiveCamera();
if (!cam)
{
return 0;
}
//Ray length
double rayLength = cam->GetClippingRange()[1];
//Ray end point
double p1[4];
p1[0] = p0[0] + rayLength * rayDirection[0];
p1[1] = p0[1] + rayLength * rayDirection[1];
p1[2] = p0[2] + rayLength * rayDirection[2];
p1[3] = 1.0;
//Construct the ray
double ray[3];
ray[0] = p1[0] - p0[0];
ray[1] = p1[1] - p0[1];
ray[2] = p1[2] - p0[2];
vtkAssemblyPath *result = nullptr;
vtkAssemblyPath *insideResult = nullptr;
vtkCollectionSimpleIterator pit;
vtkProp *prop = nullptr;
vtkAssemblyPath *path;
vtkProp *propCandidate;
double t_min = VTK_DOUBLE_MAX;
double hitPos[3] = {0.0, 0.0, 0.0};
//For all props, return the closest prop intersected by the ray.
//If we pick inside a prop, it will be returned only if no other vtkProps are
//intersected by the ray. WARNING: Intersection checking uses bounds. This is
//confusing when the prop isn't fully filling its bounds. Improve this by :
//-returning the prop which bounds center is the closest to the ray, or
//-computing intersection with the geometry itself (see vtkCellPicker).
for (propCollection->InitTraversal(pit);
(prop = propCollection->GetNextProp(pit));)
{
for (prop->InitPathTraversal(); (path = prop->GetNextPath());)
{
propCandidate = path->GetFirstNode()->GetViewProp();
if (propCandidate->GetPickable() && propCandidate->GetVisibility()
&& propCandidate->GetUseBounds())
{
double *bnds = propCandidate->GetBounds();
if (bnds)
{
double t;
double xyz[3];
//Check for box intersection
if (vtkBox::IntersectBox(bnds, const_cast<double*>(p0), ray, xyz, t))
{
//Inside a prop, save its path in case nothing else is picked
if (!(t > 0))
{
insideResult = path;
hitPos[0] = selectionPt[0];
hitPos[1] = selectionPt[1];
hitPos[2] = selectionPt[2];
}
//Something was picked by the ray, save its path and update t_min
if (t > 0 && t < t_min)
{
result = path;
t_min = t;
hitPos[0] = xyz[0];
hitPos[1] = xyz[1];
hitPos[2] = xyz[2];
}
}
}
}
}
}
// If the ray didn't intersect anything, we might be inside a prop
if (!result)
{
result = insideResult;
}
// If something was picked..
if (result)
{
result->GetFirstNode()->GetViewProp()->Pick();
this->InvokeEvent(vtkCommand::PickEvent, nullptr);
//Update the picked position
this->PickPosition[0] = hitPos[0];
this->PickPosition[1] = hitPos[1];
this->PickPosition[2] = hitPos[2];
}
this->SetPath(result);
this->InvokeEvent(vtkCommand::EndPickEvent, nullptr);
// Call Pick on the Prop that was picked, and return 1 for success
if (result)
{
return 1;
}
else
{
return 0;
}
}
void vtkPropPicker::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -90,6 +90,19 @@ public:
int PickProp3DPoint(double pos[3], vtkRenderer *renderer,
vtkPropCollection* pickfrom);
/**
* Perform a pick from the user-provided list of vtkProps.
*/
virtual int PickProp3DRay(double selectionPt[3], double eventWorldOrientation[4],
vtkRenderer *renderer, vtkPropCollection* pickfrom);
/**
* Perform pick operation with selection point provided. The
* selectionPt is in world coordinates.
* Return non-zero if something was successfully picked.
*/
int Pick3DRay(double selectionPt[3], double orient[4], vtkRenderer *ren) override;
protected:
vtkPropPicker();
~vtkPropPicker() override;
......
......@@ -26,17 +26,17 @@ PURPOSE. See the above copyright notice for more information.
#ifndef vtkOpenVRHardwarePicker_h
#define vtkOpenVRHardwarePicker_h
#include "vtkPropPicker.h"
#include "vtkRenderingOpenVRModule.h" // For export macro
#include "vtkOpenVRPropPicker.h"
class vtkSelection;
class VTKRENDERINGOPENVR_EXPORT vtkOpenVRHardwarePicker : public vtkOpenVRPropPicker
class VTKRENDERINGOPENVR_EXPORT vtkOpenVRHardwarePicker : public vtkPropPicker
{
public:
static vtkOpenVRHardwarePicker *New();
vtkTypeMacro(vtkOpenVRHardwarePicker, vtkOpenVRPropPicker);
vtkTypeMacro(vtkOpenVRHardwarePicker, vtkPropPicker);
void PrintSelf(ostream& os, vtkIndent indent) override;
......
......@@ -37,7 +37,6 @@ PURPOSE. See the above copyright notice for more information.
#include "vtkOpenVRCamera.h"
#include "vtkOpenVRControlsHelper.h"
#include "vtkOpenVRHardwarePicker.h"
#include "vtkOpenVRPropPicker.h"
#include "vtkOpenVRRenderWindow.h"
#include "vtkOpenVRRenderWindowInteractor.h"
#include "vtkOpenVRModel.h"
......@@ -46,6 +45,7 @@ PURPOSE. See the above copyright notice for more information.
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkPropPicker.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkSelection.h"
......@@ -65,10 +65,6 @@ vtkStandardNewMacro(vtkOpenVRInteractorStyle);
//----------------------------------------------------------------------------
vtkOpenVRInteractorStyle::vtkOpenVRInteractorStyle()
{
// override the base class picker
this->InteractionPicker->Delete();
this->InteractionPicker = vtkOpenVRPropPicker::New();
for (int d = 0; d < vtkEventDataNumberOfDevices; ++d)
{
this->InteractionState[d] = VTKIS_NONE;
......@@ -917,9 +913,7 @@ void vtkOpenVRInteractorStyle::UpdateRay(vtkEventDataDevice controller)
//Compute ray length.
double p1[3];
vtkOpenVRPropPicker* picker =
static_cast< vtkOpenVRPropPicker* >(this->InteractionPicker);
picker->PickProp3DRay(p0, wxyz, ren, ren->GetViewProps());
this->InteractionPicker->PickProp3DRay(p0, wxyz, ren, ren->GetViewProps());
//If something is picked, set the length accordingly
if (this->InteractionPicker->GetProp3D())
......
......@@ -39,167 +39,12 @@ vtkOpenVRPropPicker::~vtkOpenVRPropPicker()
// set up for a pick
void vtkOpenVRPropPicker::Initialize()
{
#ifndef VTK_LEGACY_SILENT
vtkErrorMacro("This class is deprecated: Please use vtkPropPicker directly instead of this class");
#endif
this->vtkAbstractPropPicker::Initialize();
}
// Pick from the given collection
int vtkOpenVRPropPicker::Pick3DRay(double pos[3], double wori[4], vtkRenderer *renderer)
{
//Compute event orientation
vtkRenderWindowInteractor3D* iren = vtkRenderWindowInteractor3D::SafeDownCast(
renderer->GetRenderWindow()->GetInteractor());
if (!iren)
{
vtkErrorMacro(<< "Couldn't get 3D interactor");
return 0;
}
if (this->PickFromList)
{
return this->PickProp3DRay(pos, wori, renderer,
this->PickList);
}
else
{
return this->PickProp3DRay(pos, wori, renderer,
renderer->GetViewProps());
}
}
// Pick from the given collection
int vtkOpenVRPropPicker::PickProp3DRay(
double selectionPt[3], double wori[4],
vtkRenderer *renderer, vtkPropCollection* propCollection)
{
// Initialize picking process
this->Initialize();
this->Renderer = renderer;
// Invoke start pick method if defined
this->InvokeEvent(vtkCommand::StartPickEvent, nullptr);
//Event position - Ray start position
double p0[4];
p0[0] = selectionPt[0];
p0[1] = selectionPt[1];
p0[2] = selectionPt[2];
p0[3] = 1.0;
//Compute ray direction
vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
trans->RotateWXYZ(wori[0], wori[1], wori[2], wori[3]);
double* rayDirection = trans->TransformDoubleVector(0.0, 0.0, -1.0);
vtkCamera* cam = renderer->GetActiveCamera();
if (!cam)
{
return 0;
}
//Ray length
double rayLength = cam->GetClippingRange()[1];
//Ray end point
double p1[4];
p1[0] = p0[0] + rayLength * rayDirection[0];
p1[1] = p0[1] + rayLength * rayDirection[1];
p1[2] = p0[2] + rayLength * rayDirection[2];
p1[3] = 1.0;
//Construct the ray
double ray[3];
ray[0] = p1[0] - p0[0];
ray[1] = p1[1] - p0[1];
ray[2] = p1[2] - p0[2];
vtkAssemblyPath *result = nullptr;
vtkAssemblyPath *insideResult = nullptr;
vtkCollectionSimpleIterator pit;
vtkProp *prop = nullptr;
vtkAssemblyPath *path;
vtkProp *propCandidate;
double t_min = VTK_DOUBLE_MAX;
double hitPos[3];
//For all props, return the closest prop intersected by the ray.
//If we pick inside a prop, it will be returned only if no other vtkProps are
//intersected by the ray. WARNING: Intersection checking uses bounds. This is
//confusing when the prop isn't fully filling its bounds. Improve this by :
//-returning the prop which bounds center is the closest to the ray, or
//-computing intersection with the geometry itself (see vtkCellPicker).
for (propCollection->InitTraversal(pit);
(prop = propCollection->GetNextProp(pit));)
{
for (prop->InitPathTraversal(); (path = prop->GetNextPath());)
{
propCandidate = path->GetFirstNode()->GetViewProp();
if (propCandidate->GetPickable() && propCandidate->GetVisibility()
&& propCandidate->GetUseBounds())
{
double *bnds = propCandidate->GetBounds();
if (bnds)
{
double t;
double xyz[3];
//Check for box intersection
if (vtkBox::IntersectBox(bnds, const_cast<double*>(p0), ray, xyz, t))
{
//Inside a prop, save its path in case nothing else is picked
if (!(t > 0))
{
insideResult = path;
hitPos[0] = selectionPt[0];
hitPos[1] = selectionPt[1];
hitPos[2] = selectionPt[2];
}
//Something was picked by the ray, save its path and update t_min
if (t > 0 && t < t_min)
{
result = path;
t_min = t;
hitPos[0] = xyz[0];
hitPos[1] = xyz[1];
hitPos[2] = xyz[2];
}
}
}
}
}
}
// If the ray didn't intersect anything, we might be inside a prop
if (!result)
{
result = insideResult;
}
// If something was picked..
if (result)
{
result->GetFirstNode()->GetViewProp()->Pick();
this->InvokeEvent(vtkCommand::PickEvent, nullptr);
//Update the picked position
this->PickPosition[0] = hitPos[0];
this->PickPosition[1] = hitPos[1];
this->PickPosition[2] = hitPos[2];
}
this->SetPath(result);
this->InvokeEvent(vtkCommand::EndPickEvent, nullptr);
// Call Pick on the Prop that was picked, and return 1 for success
if (result)
{
return 1;
}
else
{
return 0;
}
}
void vtkOpenVRPropPicker::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
......
......@@ -14,17 +14,7 @@ PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkOpenVRPropPicker
* @brief pick an actor/prop given a controller position and orientation
*
* vtkOpenVRPropPicker is used to pick an actor/prop along a ray.
* The ray position and orientation are defined by the event position and
* orientation in world coordinate.
* This class stores the picked actor/prop and the picked position in world
* coordinates; point and cell ids are not determined.
* This is useful for VRE devices that provide 3D positions and orientation.
*
* @sa
* vtkProp3DPicker vtkOpenVRInteractorStylePointer
* @brief Deprecated. Use vtkPropPicker directly
*/
#ifndef vtkOpenVRPropPicker_h
......@@ -44,19 +34,6 @@ public:
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Perform a pick from the user-provided list of vtkProps.
*/
virtual int PickProp3DRay(double selectionPt[3], double eventWorldOrientation[4],
vtkRenderer *renderer, vtkPropCollection* pickfrom);
/**
* Perform pick operation with selection point provided. The
* selectionPt is in world coordinates.
* Return non-zero if something was successfully picked.
*/
int Pick3DRay(double selectionPt[3], double orient[4], vtkRenderer *ren) override;
protected:
vtkOpenVRPropPicker();
~vtkOpenVRPropPicker() override;
......
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