Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 44 additions & 31 deletions Packages/vcs/Lib/vcs2vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,51 +857,64 @@ def prepFillarea(renWin,ren,farea,cmap=None):
n = prepPrimitive(farea)
if n==0:
return

# Find color map:
if cmap is None:
if farea.colormap is not None:
cmap = farea.colormap
else:
cmap = 'default'
if isinstance(cmap,str):
cmap = vcs.elements["colormap"][cmap]

# Create data structures:
pts = vtk.vtkPoints()
polygons = vtk.vtkCellArray()
colors = vtk.vtkUnsignedCharArray()
colors.SetNumberOfComponents(3)
colors.SetNumberOfTuples(n)
polygonPolyData = vtk.vtkPolyData()
polygonPolyData.SetPoints(pts)
polygonPolyData.SetPolys(polygons)
polygonPolyData.GetCellData().SetScalars(colors)

# Reuse this temporary container to avoid reallocating repeatedly:
polygon = vtk.vtkPolygon()

# Iterate through polygons:
for i in range(n):
x = farea.x[i]
y = farea.y[i]
c = farea.color[i]
st = farea.style[i]
idx = farea.index[i]
N = max(len(x),len(y))

for a in [x,y]:
while len(a)<n:
a.append(a[-1])
#Create points
pts = vtk.vtkPoints()
for j in range(N):
pts.InsertNextPoint(x[j],y[j],0.)
#Create polygon out of these points
polygon = vtk.vtkPolygon()
assert(len(a) == N)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces the a.append(a[-1]) line, since it seems to me that if these don't match, it's a bug. I can change this back if it is needed, though it isn't causing any test failures this way.

If we revert it, make sure not to revert the bug I fixed in the first patch of this branch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dlonie I think what the code was trying to before was filling the list to make their length match. Using the last elements. I think your change would break things like:
fa.x = [.25,.75]
fa.y = [1,]

But you are probably right it is probably better to simply error exit in such cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If having different lengths of x/y are supported, then yes, we should revert it. But otherwise, padding out the arrays with the last value will mask errors and produce invalid results, rather than let the user know something went wrong.

I'm not sure what you mean by removing the lines that create the points, which lines are you referring to?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forget my comment about lines gone, I didn't see the upper bit of the code. And yes let's not approve the array padding. Running ctest on your branch and approving.


# Add current polygon
pid = polygon.GetPointIds()
pid.SetNumberOfIds(N)
for j in range(N):
pid.SetId(j,j)
polygons = vtk.vtkCellArray()
polygons.InsertNextCell(polygon)
pid.SetId(j, pts.InsertNextPoint(x[j],y[j],0.))
cellId = polygons.InsertNextCell(polygon)

polygonPolyData = vtk.vtkPolyData()
geo,pts = project(pts,farea.projection,farea.worldcoordinate)
polygonPolyData.SetPoints(pts)
polygonPolyData.SetPolys(polygons)
# Add the color to the color array:
color = cmap.index[c]
colors.SetTupleValue(cellId, [int((C/100.) * 255) for C in color])

a = vtk.vtkActor()
m = vtk.vtkPolyDataMapper()
m.SetInputData(polygonPolyData)
a.SetMapper(m)
p = a.GetProperty()
# Transform points:
geo,pts = project(pts,farea.projection,farea.worldcoordinate)

if cmap is None:
if farea.colormap is not None:
cmap = farea.colormap
else:
cmap = 'default'
if isinstance(cmap,str):
cmap = vcs.elements["colormap"][cmap]
color = cmap.index[c]
p.SetColor([C/100. for C in color])
ren.AddActor(a)
fitToViewport(a,ren,farea.viewport,wc=farea.worldcoordinate,geo=geo)
# Setup rendering
m = vtk.vtkPolyDataMapper()
m.SetInputData(polygonPolyData)
a = vtk.vtkActor()
a.SetMapper(m)

fitToViewport(a,ren,farea.viewport,wc=farea.worldcoordinate,geo=geo)
ren.AddActor(a)
return

def genPoly(coords,pts,filled=True):
Expand Down