I have some scalar field for which I want to represent contours for +v and -v simultaneously, with different colors, with the caveat that the contours for -v should be “reversed”, i.e., they enclose the volume for which the field is > -v (rather than < -v). This could be done by representing abs(field), and coloring according to sign(field). However, I’d also like to be able to show/hide the two signs separately, for which actually having two contour values is more convenient.
Actually just displaying the contours for +v and -v looks fine… with the surface representation. But with wireframe/points, or by enabling backface culling the problems show up and it is evident that the contours for -v are reversed. Is there some solution for this? Can I have a ReverseSense filter that affects only the negative contours? Other ideas?
So far, the following seems to work (python syntax). Where I had:
c = vtk.vtkContourFilter()
c.SetInputData(points)
m = vtk.vtkPolyDataMapper()
m.SetInputConnection(c.GetOutputPort())
I replace it with:
c = vtk.vtkContourFilter()
c.SetInputData(points)
# Now split positive and negative parts
pos = vtk.vtkClipPolyData()
pos.SetInputConnection(c.GetOutputPort())
neg = vtk.vtkClipPolyData()
neg.InsideOutOn()
neg.SetInputConnection(c.GetOutputPort())
# Reverse the negative part
rvneg = vtk.vtkReverseSense()
rvneg.SetInputConnection(neg.GetOutputPort())
rvneg.ReverseCellsOn()
rvneg.ReverseNormalsOn()
# Join both parts again
tot = vtk.vtkAppendPolyData()
tot.AddInputConnection(pos.GetOutputPort())
tot.AddInputConnection(rvneg.GetOutputPort())
# And continue as before
m = vtk.vtkPolyDataMapper()
m.SetInputConnection(tot.GetOutputPort())
But I wonder if there is a more direct path. Ideally, one should be able to reverse individual contours generated by ContourFilter, since the user may have a good idea of what should be “inside” or “outside” for each one.