[vtk-developers] Picking problem with OpenGL2 and DepthPeeling
Xabi Riobe
xabivtk at gmail.com
Thu Sep 24 05:29:24 EDT 2015
Hi,
I try to pick in a scene that contains a translucent object and the pick
fails if I use the OpenGL2 backend (v6.3.0), tested on VS2013 32 bits with
nVidia Quadro 4000 (driver 353.30)
The same code works with OpenGL backend.
I can reproduce it with the sample code attached, based on the example at
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/Picking with these
lines added:
renderer->SetUseDepthPeeling(1);
renderer->SetMaximumNumberOfPeels(8);
renderWindow->SetAlphaBitPlanes(1);
renderWindow->SetMultiSamples(0);
and the opacity set to 0.5 for the plane.
If i don't use depth peeling, or if the plane is opaque, the picker works
as expected.
It seems that the pick fails when in vtkOpenGLRenderer::DonePick the float
value returned by GetZbufferData is 1.0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20150924/cbb3a162/attachment.html>
-------------- next part --------------
#include <vtkSmartPointer.h>
#include <vtkActor.h>
#include <vtkSphereSource.h>
#include <vtkRendererCollection.h>
#include <vtkCellArray.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkObjectFactory.h>
#include <vtkPlaneSource.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkPropPicker.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
// Handle mouse events
class MouseInteractorStyle2 : public vtkInteractorStyleTrackballCamera
{
public:
static MouseInteractorStyle2* New();
vtkTypeMacro(MouseInteractorStyle2, vtkInteractorStyleTrackballCamera);
virtual void OnLeftButtonDown()
{
int* clickPos = this->GetInteractor()->GetEventPosition();
// Pick from this location.
vtkSmartPointer<vtkPropPicker> picker =
vtkSmartPointer<vtkPropPicker>::New();
picker->Pick(clickPos[0], clickPos[1], 0, this->GetDefaultRenderer());
double* pos = picker->GetPickPosition();
std::cout << "Pick position (world coordinates) is: "
<< pos[0] << " " << pos[1]
<< " " << pos[2] << std::endl;
std::cout << "Picked actor: " << picker->GetActor() << std::endl;
//Create a sphere
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetCenter(pos[0], pos[1], pos[2]);
sphereSource->SetRadius(0.1);
//Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
//this->GetInteractor()->GetRenderWindow()->GetRenderers()->GetDefaultRenderer()->AddActor(actor);
this->GetDefaultRenderer()->AddActor(actor);
// Forward events
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
private:
};
vtkStandardNewMacro(MouseInteractorStyle2);
int main(int, char *[])
{
vtkSmartPointer<vtkPlaneSource> planeSource =
vtkSmartPointer<vtkPlaneSource>::New();
planeSource->Update();
// Create a polydata object
vtkPolyData* polydata = planeSource->GetOutput();
// Create a mapper
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
mapper->SetInput(polydata);
#else
mapper->SetInputData(polydata);
#endif
// Create an actor
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
//actor->GetProperty()->SetOpacity(0.5);
std::cout << "Actor address: " << actor << std::endl;
// A renderer and render window
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
////////////////////////////////////////
// BUG : no picking !!!
////////////////////////////////////////
renderer->SetUseDepthPeeling(1);
renderer->SetMaximumNumberOfPeels(8);
renderWindow->SetAlphaBitPlanes(1);
renderWindow->SetMultiSamples(0);
////////////////////////////////////////
// An interactor
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// Set the custom stype to use for interaction.
vtkSmartPointer<MouseInteractorStyle2> style =
vtkSmartPointer<MouseInteractorStyle2>::New();
style->SetDefaultRenderer(renderer);
renderWindowInteractor->SetInteractorStyle(style);
// Add the actors to the scene
renderer->AddActor(actor);
renderer->SetBackground(0, 0, 1);
// Render and interact
renderWindow->Render();
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
More information about the vtk-developers
mailing list