Commit f24894b7 authored by Andras Lasso's avatar Andras Lasso Committed by Kitware Robot

Merge topic 'fix-label-placement-mapper-culling'

64e866bb Fix disappearing labels when anchor points are not in world
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !5567
parents 3e4915f4 64e866bb
Pipeline #138337 failed with stage
in 0 seconds
a41b16db4b06b90d9fdffbd0ccf2d97c8ac9872b890c08524fe240bb9f128bf8cbbfb5256525ab3605958c4537f7a990735c7b45e24c0128e3a8c37251839b49
e70e446af6fda827ace8376633da51633d00c7dc8ad3a425fdf73975e6d7050a51a25637c2facf3854171c954e7df03788d208e3e536c9c17127b715f2c26564
d81a03303e0be82ce0447eb73974fdeed1d99756e73d281b3994aa007985cd79abfc4294e259fac3572cd10cdb69cb112204d5b09863124ee195a551b8cee76c
......@@ -2553,3 +2553,62 @@ void vtkLabelHierarchy::Implementation::SmudgeAnchor3( HierarchyCursor3& cursor,
(void)anchor;
(void)x;
}
void vtkLabelHierarchy::GetAnchorFrustumPlanes(double frustumPlanes[24], vtkRenderer* ren, vtkCoordinate* anchorTransform)
{
// We set infinitely large frustum (disable clipping) for all coordinate systems other than world
// and normalized coordinate systems.
// To improve performance, accurate view frustum could be computed for all other coordinate systems, too
// (such as DISPLAY, VIEWPORT, VIEW, POSE - see vtkCoordinate).
int coordinateSystem = anchorTransform->GetCoordinateSystem();
if (coordinateSystem == VTK_WORLD)
{
vtkCamera* cam = ren->GetActiveCamera();
if (cam)
{
cam->GetFrustumPlanes(ren->GetTiledAspectRatio(), frustumPlanes);
return;
}
}
double minPosition = VTK_DOUBLE_MAX;
double maxPosition = VTK_DOUBLE_MAX;
if (coordinateSystem == VTK_NORMALIZED_DISPLAY
|| coordinateSystem == VTK_NORMALIZED_VIEWPORT)
{
minPosition = 0.0;
maxPosition = 1.0;
}
frustumPlanes[0] = 1.0;
frustumPlanes[1] = 0.0;
frustumPlanes[2] = 0.0;
frustumPlanes[3] = minPosition;
frustumPlanes[4] = -1.0;
frustumPlanes[5] = 0.0;
frustumPlanes[6] = 0.0;
frustumPlanes[7] = maxPosition;
frustumPlanes[8] = 0.0;
frustumPlanes[9] = 1.0;
frustumPlanes[10] = 0.0;
frustumPlanes[11] = minPosition;
frustumPlanes[12] = 0.0;
frustumPlanes[13] = -1.0;
frustumPlanes[14] = 0.0;
frustumPlanes[15] = maxPosition;
frustumPlanes[16] = 0.0;
frustumPlanes[17] = 0.0;
frustumPlanes[18] = -1.0;
frustumPlanes[19] = VTK_DOUBLE_MAX;
frustumPlanes[20] = 0.0;
frustumPlanes[21] = 0.0;
frustumPlanes[22] = 1.0;
frustumPlanes[23] = VTK_DOUBLE_MAX;
}
......@@ -67,6 +67,7 @@
class vtkAbstractArray;
class vtkCamera;
class vtkCoincidentPoints;
class vtkCoordinate;
class vtkDataArray;
class vtkIntArray;
class vtkLabelHierarchyIterator;
......@@ -248,6 +249,15 @@ public:
vtkGetObjectMacro(CoincidentPoints,vtkCoincidentPoints);
//@}
//@{
/**
* Compute frustum for quickly excluding labels from rendering
* that are outside the visible region.
* This is a shared utility function.
*/
static void GetAnchorFrustumPlanes(double frustumPlanes[24], vtkRenderer* ren, vtkCoordinate* anchorTransform);
//@}
protected:
vtkLabelHierarchy();
~vtkLabelHierarchy() override;
......
......@@ -590,9 +590,11 @@ void vtkLabelPlacementMapper::RenderOverlay(vtkViewport *viewport,
double sz[4];
int origin[2];
int dispx[2];
// Compute frustum for excluding labels that are outside the visible region.
double frustumPlanes[24];
double aspect = ren->GetTiledAspectRatio();
cam->GetFrustumPlanes( aspect, frustumPlanes );
vtkLabelHierarchy::GetAnchorFrustumPlanes(frustumPlanes, ren, this->AnchorTransform);
unsigned long allowableLabelArea = static_cast<unsigned long>
( ( ( kdbounds[1] - kdbounds[0] ) * ( kdbounds[3] - kdbounds[2] ) ) * this->MaximumLabelFraction );
(void)allowableLabelArea;
......@@ -663,31 +665,35 @@ void vtkLabelPlacementMapper::RenderOverlay(vtkViewport *viewport,
}
inIter->GetPoint( x );
// Cull points behind the camera. Cannot rely on hither-yon planes because the camera
// position gets changed during vtkInteractorStyle::Dolly() and RequestData() called from
// within ResetCameraClippingRange() before the frustum planes are updated.
// Cull points outside hither-yon planes (other planes get tested below)
double* eye = cam->GetPosition();
double* dir = cam->GetViewPlaneNormal();
if ( ( x[0] - eye[0] ) * dir[0] + ( x[1] - eye[1] ) * dir[1] + ( x[2] - eye[2] ) * dir[2] > 0 )
{
continue;
}
// Ignore labels pointing the wrong direction (HACK)
if ( this->PositionsAsNormals )
if (this->AnchorTransform->GetCoordinateSystem() == VTK_WORLD)
{
if ( camVec[0] * x[0] + camVec[1] * x[1] + camVec[2] * x[2] < 0. )
// Cull points behind the camera. Cannot rely on hither-yon planes because the camera
// position gets changed during vtkInteractorStyle::Dolly() and RequestData() called from
// within ResetCameraClippingRange() before the frustum planes are updated.
// Cull points outside hither-yon planes (other planes get tested below)
double* eye = cam->GetPosition();
double* dir = cam->GetViewPlaneNormal();
if ((x[0] - eye[0]) * dir[0] + (x[1] - eye[1]) * dir[1] + (x[2] - eye[2]) * dir[2] > 0)
{
continue;
}
}
// Test for occlusion using the z-buffer
if (this->UseDepthBuffer && !this->VisiblePoints->IsPointOccluded(x, zPtr))
{
occluded++;
continue;
// Ignore labels pointing the wrong direction (HACK)
if (this->PositionsAsNormals)
{
if (camVec[0] * x[0] + camVec[1] * x[1] + camVec[2] * x[2] < 0.)
{
continue;
}
}
// Test for occlusion using the z-buffer
if (this->UseDepthBuffer && !this->VisiblePoints->IsPointOccluded(x, zPtr))
{
occluded++;
continue;
}
}
this->AnchorTransform->SetValue( x );
......@@ -735,7 +741,7 @@ void vtkLabelPlacementMapper::RenderOverlay(vtkViewport *viewport,
ur[0] = dispx[0] + sz[0];
ur[1] = dispx[1] + sz[1];
if ( ll[1] > kdbounds[3] || ur[1] < kdbounds[2] || ll[0] > kdbounds[1] || ur[1] < kdbounds[0] )
if (ll[1] > kdbounds[3] || ur[1] < kdbounds[2] || ll[0] > kdbounds[1] || ur[0] < kdbounds[0])
{
continue; // cull label not in frame
}
......
......@@ -553,9 +553,11 @@ int vtkLabelPlacer::RequestData(
double x[3];
double sz[4];
int* dispx;
// Compute frustum for excluding labels that are outside the visible region.
double frustumPlanes[24];
double aspect = this->Renderer->GetTiledAspectRatio();
cam->GetFrustumPlanes( aspect, frustumPlanes );
vtkLabelHierarchy::GetAnchorFrustumPlanes(frustumPlanes, this->Renderer, this->AnchorTransform);
unsigned long allowableLabelArea = static_cast<unsigned long>
( ( ( kdbounds[1] - kdbounds[0] ) * ( kdbounds[3] - kdbounds[2] ) ) * this->MaximumLabelFraction );
(void)allowableLabelArea;
......@@ -604,31 +606,35 @@ int vtkLabelPlacer::RequestData(
}
inIter->GetPoint( x );
// Cull points behind the camera. Cannot rely on hither-yon planes because the camera
// position gets changed during vtkInteractorStyle::Dolly() and RequestData() called from
// within ResetCameraClippingRange() before the frustum planes are updated.
// Cull points outside hither-yon planes (other planes get tested below)
double* eye = cam->GetPosition();
double* dir = cam->GetViewPlaneNormal();
if ( ( x[0] - eye[0] ) * dir[0] + ( x[1] - eye[1] ) * dir[1] + ( x[2] - eye[2] ) * dir[2] > 0 )
{
continue;
}
// Ignore labels pointing the wrong direction (HACK)
if ( this->PositionsAsNormals )
if (this->AnchorTransform->GetCoordinateSystem() == VTK_WORLD)
{
if ( camVec[0] * x[0] + camVec[1] * x[1] + camVec[2] * x[2] < 0. )
// Cull points behind the camera. Cannot rely on hither-yon planes because the camera
// position gets changed during vtkInteractorStyle::Dolly() and RequestData() called from
// within ResetCameraClippingRange() before the frustum planes are updated.
// Cull points outside hither-yon planes (other planes get tested below)
double* eye = cam->GetPosition();
double* dir = cam->GetViewPlaneNormal();
if ((x[0] - eye[0]) * dir[0] + (x[1] - eye[1]) * dir[1] + (x[2] - eye[2]) * dir[2] > 0)
{
continue;
}
}
// Test for occlusion using the z-buffer
if (this->UseDepthBuffer && !this->VisiblePoints->IsPointOccluded(x, zPtr))
{
occluded++;
continue;
// Ignore labels pointing the wrong direction (HACK)
if (this->PositionsAsNormals)
{
if (camVec[0] * x[0] + camVec[1] * x[1] + camVec[2] * x[2] < 0.)
{
continue;
}
}
// Test for occlusion using the z-buffer
if (this->UseDepthBuffer && !this->VisiblePoints->IsPointOccluded(x, zPtr))
{
occluded++;
continue;
}
}
this->AnchorTransform->SetValue( x );
......
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