Skip to content

Commit d7ea751

Browse files
committed
fix: make highlights render while edge visibility on in client mode
1 parent 3a5657a commit d7ea751

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎src/ansys/visor/viewer/vtk/node_pipeline.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
LOOKUP_TABLE_HUE_RANGE: tuple[float, float] = (0.667, 0.0)
3838
"""Blue (low) to red (high)."""
3939

40+
PART_POLYGON_OFFSET: tuple[float, float] = (0.0, 2.0)
41+
"""Relative coincident-topology polygon offset (factor, units) for every part.
42+
43+
Applied by VTK only while the part is drawn with edges on. Positive values push
44+
the part's faces away from the camera, so geometry drawn on faces without an offset
45+
(the geometry highlight) draws in front of the part's faces.
46+
47+
When part edges are on, With a zero polygon offset, the highlight is drawn behind the
48+
face and is invisible.
49+
"""
4050

4151
@dataclass
4252
class VtkNodePipeline:
@@ -80,6 +90,7 @@ def from_dataset(cls, dataset: vtkDataObject) -> "VtkNodePipeline":
8090
mapper.SetInputConnection(base_algorithm.GetOutputPort())
8191
lookup_table = cls._create_lookup_table()
8292
mapper.SetLookupTable(lookup_table)
93+
mapper.SetRelativeCoincidentTopologyPolygonOffsetParameters(*PART_POLYGON_OFFSET)
8394

8495
actor = vtkActor()
8596
actor.SetMapper(mapper)

‎tests/unit/vtk/test_node_pipeline.py‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from unittest.mock import MagicMock, patch
55

66
import pytest
7-
from vtkmodules.vtkCommonCore import vtkFloatArray
7+
from vtkmodules.vtkCommonCore import reference, vtkFloatArray
88
from vtkmodules.vtkCommonDataModel import vtkPlane, vtkPolyData, vtkUnstructuredGrid
99
from vtkmodules.vtkFiltersCore import vtkAppendPolyData
1010
from vtkmodules.vtkFiltersGeometry import vtkGeometryFilter
@@ -14,7 +14,7 @@
1414

1515
from ansys.visor.viewer.core.visor_colors import VisorColors
1616
from ansys.visor.viewer.core.visor_enums import VisorVtkVariableType
17-
from ansys.visor.viewer.vtk.node_pipeline import VtkNodePipeline
17+
from ansys.visor.viewer.vtk.node_pipeline import PART_POLYGON_OFFSET, VtkNodePipeline
1818

1919

2020
@pytest.fixture
@@ -112,6 +112,28 @@ def test_from_dataset_sets_default_color_and_flat_shading(poly_dataset):
112112
assert pipe.actor.GetProperty().GetInterpolation() == 0
113113

114114

115+
def test_from_dataset_pushes_faces_back_with_relative_polygon_offset(poly_dataset):
116+
"""The part's faces are pushed back so that edges and highlights draw in front."""
117+
pipe = VtkNodePipeline.from_dataset(poly_dataset)
118+
factor, units = reference(0.0), reference(0.0)
119+
120+
pipe.mapper.GetRelativeCoincidentTopologyPolygonOffsetParameters(factor, units)
121+
122+
assert (factor, units) == PART_POLYGON_OFFSET
123+
124+
125+
def test_from_dataset_servers_relative_polygon_offset(poly_dataset):
126+
"""The offset is in the mapper state, so the wasm client can use when it draws the highlight."""
127+
pipe = VtkNodePipeline.from_dataset(poly_dataset)
128+
mgr = vtkObjectManager()
129+
mgr.Initialize()
130+
mgr.RegisterObject(pipe.actor)
131+
mgr.UpdateStatesFromObjects()
132+
133+
mapper_state = json.loads(mgr.GetState(mgr.GetId(pipe.mapper)))
134+
assert tuple(mapper_state["RelativeCoincidentTopologyPolygonOffsetParameters"]) == PART_POLYGON_OFFSET
135+
136+
115137
def test_from_dataset_unsupported_type_raises():
116138
with pytest.raises(RuntimeError, match="node type not yet supported"):
117139
VtkNodePipeline.from_dataset(object())

0 commit comments

Comments
 (0)