<div dir="ltr"><div><div><div><div><div>Hi vtkusers,<br><br></div>I am trying to visualize several (almost) coincident surfaces and wireframe objects using VTK 8.0 and OpenGL2 on Linux. I am providing a code snippet in Python, in which I have created two Mappers from the same object and then the corresponding Actors. One of the two actors is slighty shifted in order to simulate geometries which are not exactly coincident. Also note that I had to perform a relatively high Z scaling because the objects are geologic regional surfaces, which would appear nearly flat without proper scaling.<br><br># Surface 1 (Red)<br>surf1Mapper = vtk.vtkPolyDataMapper()<br>surf1Mapper.SetInputData(surf)<br>surf1Mapper.SetResolveCoincidentTopologyToPolygonOffset()<br>surf1Mapper.SetRelativeCoincidentTopologyPolygonOffsetParameters(-2.0, -2.0)<br><br>surf1Actor = vtk.vtkActor()<br>surf1Actor.SetMapper(surf1Mapper)<br>surf1Actor.GetProperty().SetColor(1, 0, 0)<br>surf1Actor.SetScale(1, 1, 100)<br><br></div><div># Not necessary. Only used to clarify things.<br></div><div>surf1Actor.SetPosition(0, 0, 0) <br><br># Surface 2 (Blue)<br>surf2Mapper = vtk.vtkPolyDataMapper()<br>surf2Mapper.SetInputData(surf)<br>surf2Mapper.SetResolveCoincidentTopologyToPolygonOffset()<br>surf2Mapper.SetRelativeCoincidentTopologyPolygonOffsetParameters(-4.0, -9.0)<br><br>surf2Actor = vtk.vtkActor()<br>surf2Actor.SetMapper(surf2Mapper)<br>surf2Actor.GetProperty().SetColor(0, 0, 1)<br>surf2Actor.SetScale(1, 1, 100)<br># Perform small shift in order to simulate interaction between non-coincident geometries.<br>surf2Actor.SetPosition(0, 0, 10)<br><br># Edges from surface 1. Observe that this object is not translated, so that its geometry is coincident with surface1's (which has a lower polygon offset priority compared to surface2).<br>edges = vtk.vtkExtractEdges()<br>edges.SetInputData(surf)<br>edges.Update()<br><br>edgesMapper = vtk.vtkPolyDataMapper()<br>edgesMapper.SetInputData(edges.GetOutput())<br>edgesMapper.SetResolveCoincidentTopologyToPolygonOffset()<br>edgesMapper.SetRelativeCoincidentTopologyLineOffsetParameters(-20.0, -20.0)<br><br>edgesActor = vtk.vtkActor()<br>edgesActor.SetMapper(edgesMapper)<br>edgesActor.GetProperty().SetColor(0, 0, 0)<br>edgesActor.SetScale(1, 1, 100)<br><br></div><div># Again, this is not necessary.<br></div><div>edgesActor.SetPosition(0, 0, 0)<br><br></div>To avoid Z-fighting between the surfaces' faces, I used vtkMapper:: SetResolveCoincidentTopologyToPolygonOffset() and then provided different values for the parameters factor and units, using each mapper's SetRelativeCoincidentTopology PolygonOffset Parameters() method. Surface 1 has (factor, units) = (-2, -2), whereas Surface 2 (which has drawing priority) uses (-4, -9). I had to use units = -9 because lower values would end up showing some polygons from surface 1.<br></div>Then I tried to add a wireframe object, whose geometry is the same as surface1's.<br></div>You can see in the code that I had to use high values (-20, -20) for factor and units (via the SetRelativeCoincidentTopology LineOffset Parameters() method). This was necessary because I wasn't able to see all the edges on surface2.<br><br></div>I have read Ken Martin's post explaining the difference between the factor and units parameters:<br><a href="http://markmail.org/search/?q=vtkusers+polygonoffset#query:vtkusers%20polygonoffset+page:1+mid:lpucqjdjbjz3hy53+state:results">http://markmail.org/search/?q=vtkusers+polygonoffset#query:vtkusers%20polygonoffset+page:1+mid:lpucqjdjbjz3hy53+state:results</a><br><div><br></div><div>I verified that to avoid Z-fighting issues between polygons, the factor and units parameters must have the same order of magnitude (e.g. -2, -2). Also, I have tried, whenever possible, to follow Ken's advice not to use values with magnitudes higher than (minus or plus) 10. But in the case of the wireframe object, my parameters had to be higher. And even so, I couldn't assure the visualization of all the edges, as you can see in the attached image.<br></div><div>Moreover, the problem persists even when I use exactly coincident surfaces (e.g., removing the vtkActor::SetPosition() methods. <br></div><div><br></div><div>If you have had the patience of following me until this point, I'd like to ask these questions:<br><br></div><div>1. Is is possible to specify priorities between polygon/polygon and line/polygon parameters? For example, surface 1 used (factor, units) = (-2, -2), surface 2 used (-4, -9) (PolygonOffset parameters), whereas edges used (-20, -20), the highes priority among the three objects, set using LineOffset parameters. Is this consistent?<br></div><div><div>In my application, I have Z-fighting issues among 3-4 coincident
surfaces (each with its own geologic meaning provided by different
CellData values) and also among 8-9 coincident lines. And the two groups
interact, in the sense that lines must always be drawn correctly on any
surface. Can I achieve this using VTK's Polygon Offset approach?<br></div><div><br></div>2. Would it be possible to do what I am trying to achieve using different approaches? I have tried using vtkMapper::SetResolveCoincidentTopologyZShift(), but with little success.<br></div><br><div>I know this is a very long post and apologize for that, but I have been struggling with this issue for the last two weeks. So I tried to add as much information as possible.<br></div><div><br></div><div>Thank you very much for any advice.<br></div><div><br></div><div> Luca<br></div></div>