[vtkusers] Is interaction between Polygon Offset and Line Offset parameters allowed?
Luca Pallozzi Lavorante
lplavorante at gmail.com
Thu Sep 14 10:12:12 EDT 2017
Hi vtkusers,
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.
# Surface 1 (Red)
surf1Mapper = vtk.vtkPolyDataMapper()
surf1Mapper.SetInputData(surf)
surf1Mapper.SetResolveCoincidentTopologyToPolygonOffset()
surf1Mapper.SetRelativeCoincidentTopologyPolygonOffsetParameters(-2.0, -2.0)
surf1Actor = vtk.vtkActor()
surf1Actor.SetMapper(surf1Mapper)
surf1Actor.GetProperty().SetColor(1, 0, 0)
surf1Actor.SetScale(1, 1, 100)
# Not necessary. Only used to clarify things.
surf1Actor.SetPosition(0, 0, 0)
# Surface 2 (Blue)
surf2Mapper = vtk.vtkPolyDataMapper()
surf2Mapper.SetInputData(surf)
surf2Mapper.SetResolveCoincidentTopologyToPolygonOffset()
surf2Mapper.SetRelativeCoincidentTopologyPolygonOffsetParameters(-4.0, -9.0)
surf2Actor = vtk.vtkActor()
surf2Actor.SetMapper(surf2Mapper)
surf2Actor.GetProperty().SetColor(0, 0, 1)
surf2Actor.SetScale(1, 1, 100)
# Perform small shift in order to simulate interaction between
non-coincident geometries.
surf2Actor.SetPosition(0, 0, 10)
# 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).
edges = vtk.vtkExtractEdges()
edges.SetInputData(surf)
edges.Update()
edgesMapper = vtk.vtkPolyDataMapper()
edgesMapper.SetInputData(edges.GetOutput())
edgesMapper.SetResolveCoincidentTopologyToPolygonOffset()
edgesMapper.SetRelativeCoincidentTopologyLineOffsetParameters(-20.0, -20.0)
edgesActor = vtk.vtkActor()
edgesActor.SetMapper(edgesMapper)
edgesActor.GetProperty().SetColor(0, 0, 0)
edgesActor.SetScale(1, 1, 100)
# Again, this is not necessary.
edgesActor.SetPosition(0, 0, 0)
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.
Then I tried to add a wireframe object, whose geometry is the same as
surface1's.
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.
I have read Ken Martin's post explaining the difference between the factor
and units parameters:
http://markmail.org/search/?q=vtkusers+polygonoffset#query:vtkusers%20polygonoffset+page:1+mid:lpucqjdjbjz3hy53+state:results
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.
Moreover, the problem persists even when I use exactly coincident surfaces
(e.g., removing the vtkActor::SetPosition() methods.
If you have had the patience of following me until this point, I'd like to
ask these questions:
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?
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?
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.
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.
Thank you very much for any advice.
Luca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170914/6d2d2273/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LineOffset.jpg
Type: image/jpeg
Size: 116520 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170914/6d2d2273/attachment-0001.jpg>
More information about the vtkusers
mailing list