Skip to content
/ VTK Public

Commit cff3d9a

Browse files
PauloCarvalhoRJmwestphal
authored andcommitted
vtkRenderer: Fix prop picking in GetZ method
Fixes issue https://gitlab.kitware.com/vtk/vtk/-/issues/18503.
1 parent eb51d1a commit cff3d9a

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

Rendering/Core/vtkRenderer.cxx

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,19 +1479,37 @@ void vtkRenderer::SetRenderWindow(vtkRenderWindow* renwin)
14791479
// Given a pixel location, return the Z value
14801480
double vtkRenderer::GetZ(int x, int y)
14811481
{
1482-
float* zPtr;
1483-
double z;
1484-
1485-
zPtr = this->RenderWindow->GetZbufferData(x, y, x, y);
1486-
if (zPtr)
1487-
{
1488-
z = *zPtr;
1489-
delete[] zPtr;
1490-
}
1491-
else
1492-
{
1493-
z = 1.0;
1482+
double z = 1.0;
1483+
1484+
// use a hardware selector beacuse calling this->RenderWindow->
1485+
// GetZbufferData(int,int,int,int) directly from here always
1486+
// results in a z-buffer value of 1.0, meaning it is using a
1487+
// cleared depth buffer.
1488+
{
1489+
vtkNew<vtkHardwareSelector> hsel;
1490+
hsel->SetActorPassOnly(true);
1491+
hsel->SetCaptureZValues(true);
1492+
hsel->SetRenderer(this);
1493+
hsel->SetArea(x, y, x, y);
1494+
vtkSmartPointer<vtkSelection> sel;
1495+
sel.TakeReference(hsel->Select());
1496+
1497+
// find the closest z-buffer value
1498+
if (sel && sel->GetNode(0))
1499+
{
1500+
double closestDepth = 1.0;
1501+
unsigned int numPicked = sel->GetNumberOfNodes();
1502+
for (unsigned int pIdx = 0; pIdx < numPicked; pIdx++)
1503+
{
1504+
vtkSelectionNode* selnode = sel->GetNode(pIdx);
1505+
double adepth = selnode->GetProperties()->Get(vtkSelectionNode::ZBUFFER_VALUE());
1506+
if (adepth < closestDepth)
1507+
closestDepth = adepth;
1508+
}
1509+
z = closestDepth;
1510+
}
14941511
}
1512+
14951513
return z;
14961514
}
14971515

0 commit comments

Comments
 (0)