Skip to content

Commit

Permalink
Merge pull request #1348 from UV-CDAT/vtk-master-bump
Browse files Browse the repository at this point in the history
Vtk master bump
  • Loading branch information
doutriaux1 committed Jun 2, 2015
2 parents 5aa5c8c + 722ca16 commit c6392bc
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 64 deletions.
1 change: 0 additions & 1 deletion Packages/vcs/Lib/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,6 @@ def update_input(self,vtkobjects,array1,array2=None,update=True):
ports=vtkobjects["vtk_backend_glyphfilters"]
w = vcs2vtk.generateVectorArray(array1,array2,vg)
vg.GetPointData().AddArray(w)
vg = vcs2vtk.stripGrid(vg)
ports[0].SetInputData(vg)

if vtkobjects.has_key("vtk_backend_actors"):
Expand Down
11 changes: 7 additions & 4 deletions Packages/vcs/Lib/editors/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def update(self):
del self.textboxes

self.textboxes = []
w, h = self.interactor.GetRenderWindow().GetSize()
renWin = self.interactor.GetRenderWindow()
w, h = renWin.GetSize()
dpi = renWin.GetDPI()
cmap = vcs.getcolormap()

prop = vtkTextProperty()
Expand All @@ -106,7 +108,8 @@ def update(self):
y = self.text.y[ind]
string = self.text.string[ind]

text_width, text_height = text_dimensions(self.text, ind, (w, h))
text_width, text_height = text_dimensions(self.text, ind, (w, h),
dpi)

x = x * w
y = y * h
Expand Down Expand Up @@ -291,7 +294,7 @@ def update_priority(self):
self.render()


def text_dimensions(text, index, winsize):
def text_dimensions(text, index, winsize, dpi):
prop = vtkTextProperty()
vcs.vcs2vtk.prepTextProperty(prop, winsize, text, text, vcs.getcolormap())
return vcs.vtk_ui.text.text_dimensions(text.string[index], prop)
return vcs.vtk_ui.text.text_dimensions(text.string[index], prop, dpi)
62 changes: 22 additions & 40 deletions Packages/vcs/Lib/vcs2vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ def putMaskOnVTKGrid(data,grid,actorColor=None,cellData=True,deep=True):
imsk = numpy_to_vtk_wrapper(msk.astype(numpy.int).flat,deep=deep)
mapper = None
if msk is not numpy.ma.nomask and not numpy.allclose(msk,False):
msk = numpy_to_vtk_wrapper(numpy.logical_not(msk).astype(numpy.uint8).flat,deep=deep)
nomsk = numpy_to_vtk_wrapper(numpy.ones(data.mask.shape,numpy.uint8).flat,deep=deep)
if actorColor is not None:
if grid.IsA("vtkStructuredGrid"):
grid2 = vtk.vtkStructuredGrid()
Expand All @@ -49,8 +47,8 @@ def putMaskOnVTKGrid(data,grid,actorColor=None,cellData=True,deep=True):
r,g,b = actorColor
lut.SetNumberOfTableValues(2)
if not cellData:
if grid2.IsA("vtkStructuredGrid"):
grid2.SetPointVisibilityArray(nomsk)
grid2.GetPointData().RemoveArray(
vtk.vtkDataSetAttributes.GhostArrayName())
grid2.GetPointData().SetScalars(imsk)
#grid2.SetCellVisibilityArray(imsk)
#p2c = vtk.vtkPointDataToCellData()
Expand All @@ -60,8 +58,8 @@ def putMaskOnVTKGrid(data,grid,actorColor=None,cellData=True,deep=True):
lut.SetTableValue(0,r/100.,g/100.,b/100.,1.)
lut.SetTableValue(1,r/100.,g/100.,b/100.,1.)
else:
if grid2.IsA("vtkStructuredGrid"):
grid2.SetCellVisibilityArray(nomsk)
grid2.GetCellData().RemoveArray(
vtk.vtkDataSetAttributes.GhostArrayName())
grid2.GetCellData().SetScalars(imsk)
geoFilter.SetInputData(grid2)
lut.SetTableValue(0,r/100.,g/100.,b/100.,0.)
Expand All @@ -71,11 +69,24 @@ def putMaskOnVTKGrid(data,grid,actorColor=None,cellData=True,deep=True):
mapper.SetInputData(geoFilter.GetOutput())
mapper.SetLookupTable(lut)
mapper.SetScalarRange(0,1)
if grid.IsA("vtkStructuredGrid"):
if not cellData:
grid.SetPointVisibilityArray(msk)
else:
grid.SetCellVisibilityArray(msk)

# The ghost array now stores information about hidden (blanked)
# points/cells. Setting an array entry to the bitwise value
# `vtkDataSetAttributes.HIDDEN(CELL|POINT)` will blank the cell/point.
flatMask = msk.flat
ghost = numpy.zeros(len(flatMask), dtype=numpy.uint8)
invalidMaskValue = vtk.vtkDataSetAttributes.HIDDENCELL if cellData else \
vtk.vtkDataSetAttributes.HIDDENPOINT
for i, isInvalid in enumerate(flatMask):
if isInvalid:
ghost[i] = invalidMaskValue

ghost = numpy_to_vtk_wrapper(ghost, deep=deep)
ghost.SetName(vtk.vtkDataSetAttributes.GhostArrayName())
if cellData:
grid.GetCellData().AddArray(ghost)
else:
grid.GetPointData().AddArray(ghost)
return mapper

def genGridOnPoints(data1,gm,deep=True,grid=None,geo=None):
Expand Down Expand Up @@ -1434,35 +1445,6 @@ def generateVectorArray(data1,data2,vtk_grid):
w.SetName("vectors")
return w

def stripGrid(vtk_grid):
# Strip out masked points.
if vtk_grid.IsA("vtkStructuredGrid"):
if vtk_grid.GetCellBlanking():
visArray = vtk_grid.GetCellVisibilityArray()
visArray.SetName("BlankingArray")
vtk_grid.GetCellData().AddArray(visArray)
thresh = vtk.vtkThreshold()
thresh.SetInputData(vtk_grid)
thresh.ThresholdByUpper(0.5)
thresh.SetInputArrayToProcess(0, 0, 0,
"vtkDataObject::FIELD_ASSOCIATION_CELLS",
"BlankingArray")
thresh.Update()
vtk_grid = thresh.GetOutput()
elif vtk_grid.GetPointBlanking():
visArray = vtk_grid.GetPointVisibilityArray()
visArray.SetName("BlankingArray")
vtk_grid.GetPointData().AddArray(visArray)
thresh = vtk.vtkThreshold()
thresh.SetInputData(vtk_grid)
thresh.SetUpperThreshold(0.5)
thresh.SetInputArrayToProcess(0, 0, 0,
"vtkDataObject::FIELD_ASSOCIATION_POINTS",
"BlankingArray")
thresh.Update()
vtk_grid = thresh.GetOutput()
return vtk_grid

def vtkIterate(iterator):
iterator.InitTraversal()
obj = iterator.GetNextItem()
Expand Down
2 changes: 0 additions & 2 deletions Packages/vcs/Lib/vcsvtk/vectorpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ def plot(self, data1, data2, tmpl, gm, grid, transform):
if gm.linecolor is not None:
lcolor = gm.linecolor

grid = vcs2vtk.stripGrid(grid)

arrow = vtk.vtkGlyphSource2D()
arrow.SetGlyphTypeToArrow()
arrow.FilledOff()
Expand Down
5 changes: 4 additions & 1 deletion Packages/vcs/Lib/vtk_ui/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def get_dimensions(self):

def update(self):
self.repr.SetNumberOfStates(len(self.states))
dpi = self.interactor.GetRenderWindow().GetDPI()

max_width = 0
max_height = 0
Expand All @@ -197,7 +198,9 @@ def update(self):
max_width = max(max_width, w)

elif label_text:
l_w, l_h = text_dimensions(label_text, self.text_widget.actor.GetTextProperty())
l_w, l_h = text_dimensions(
label_text, self.text_widget.actor.GetTextProperty(),
dpi)

max_height = max(max_height, l_h)
max_width = max(max_width, l_w)
Expand Down
16 changes: 10 additions & 6 deletions Packages/vcs/Lib/vtk_ui/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ def text_actor(string, fgcolor, size, font):
return actor


def text_dimensions(text, text_prop, at_angle=0):
def text_dimensions(text, text_prop, dpi, at_angle=0):
ren = vtkTextRenderer()
bounds = [0, 0, 0, 0]
p = vtkTextProperty()
p.ShallowCopy(text_prop)
p.SetOrientation(at_angle)
ren.GetBoundingBox(p, text, bounds)
ren.GetBoundingBox(p, text, bounds, dpi)
return bounds[1] - bounds[0] + 1, bounds[3] - bounds[2] + 1


Expand Down Expand Up @@ -253,7 +253,8 @@ def left(self):
if halign == "Left":
return self.x

w, h = text_dimensions(self.text, self.actor.GetTextProperty())
dpi = self.interactor.GetRenderWindow().GetDPI()
w, h = text_dimensions(self.text, self.actor.GetTextProperty(), dpi)
if halign == "Centered":
return self.x - math.floor(w / 2.)

Expand All @@ -266,7 +267,8 @@ def left(self, l):
if halign == "Left":
self.x = l

w, h = text_dimensions(self.text, self.actor.GetTextProperty())
dpi = self.interactor.GetRenderWindow().GetDPI()
w, h = text_dimensions(self.text, self.actor.GetTextProperty(), dpi)
if halign == "Centered":
self.x = l + math.floor(w / 2.)

Expand All @@ -276,7 +278,8 @@ def left(self, l):
@property
def top(self):
"""The top side of the text actor, adjusted by height/justification"""
w, h = text_dimensions(self.text, self.actor.GetTextProperty())
dpi = self.interactor.GetRenderWindow().GetDPI()
w, h = text_dimensions(self.text, self.actor.GetTextProperty(), dpi)
valign = self.actor.GetTextProperty().GetVerticalJustificationAsString()
y = self.y
# Adjust from alignment point to top of the actor
Expand All @@ -296,7 +299,8 @@ def top(self, t):
Sets actor y using distance in pixels from top of window to top of actor
"""
# Get the text's size to adjust for alignment
w, h = text_dimensions(self.text, self.actor.GetTextProperty())
dpi = self.interactor.GetRenderWindow().GetDPI()
w, h = text_dimensions(self.text, self.actor.GetTextProperty(), dpi)

valign = self.actor.GetTextProperty().GetVerticalJustificationAsString()
# Adjust position based on alignment
Expand Down
15 changes: 9 additions & 6 deletions Packages/vcs/Lib/vtk_ui/textbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,16 @@ def place_cursor(self):

rows = self.text.split("\n")

width, height = text_dimensions(self.text, prop)
dpi = self.interactor.GetRenderWindow().GetDPI()
width, height = text_dimensions(self.text, prop, dpi)
line_height = float(height) / len(rows)

column_adjustment, _ = text_dimensions(rows[self.row][:self.column], prop)
column_adjustment, _ = text_dimensions(rows[self.row][:self.column],
prop, dpi)

x += column_adjustment

row_width, _ = text_dimensions(rows[self.row], prop)
row_width, _ = text_dimensions(rows[self.row], prop, dpi)

# Adjust for blank space caused by justifications
halign = prop.GetJustificationAsString()
Expand Down Expand Up @@ -256,7 +258,8 @@ def row_col_at_point(self, x, y):
rows = self.text.split("\n")
prop = self.actor.GetTextProperty()

text_width, text_height = text_dimensions(self.text, prop)
dpi = self.interactor.GetRenderWindow().GetDPI()
text_width, text_height = text_dimensions(self.text, prop, dpi)

# Viewport coordinates of widget
sw, sh = self.interactor.GetRenderWindow().GetSize()
Expand Down Expand Up @@ -292,7 +295,7 @@ def row_col_at_point(self, x, y):
else:
dim_row = row

w, h = text_dimensions(dim_row, prop)
w, h = text_dimensions(dim_row, prop, dpi)
row_bounds.append((w, h))

if w > max_width:
Expand Down Expand Up @@ -344,7 +347,7 @@ def row_col_at_point(self, x, y):
w = 0
ind = 1
while row_left + w < x:
w, _ = text_dimensions(text[:ind], prop)
w, _ = text_dimensions(text[:ind], prop, dpi)
ind += 1

return row_at_point, ind - 1
Expand Down
4 changes: 3 additions & 1 deletion testing/vcs/vtk_ui/test_vtk_ui_label_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
class test_vtk_ui_label_bounds(vtk_ui_test):
def do_test(self):
self.win.SetSize(130, 40)
dpi = self.win.GetDPI()

l = vcs.vtk_ui.Label(self.inter, "Testing", fgcolor=(0, 0, 0), size=24, font="Arial")
l.show()
w, h = vcs.vtk_ui.text.text_dimensions("Testing", l.actor.GetTextProperty())
w, h = vcs.vtk_ui.text.text_dimensions("Testing",
l.actor.GetTextProperty(), dpi)

left = l.left

Expand Down
10 changes: 7 additions & 3 deletions testing/vcs/vtk_ui/test_vtk_ui_text_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ def do_test(self):
text_property = vtk.vtkTextProperty()
text_property.SetFontFamilyToArial()
text_property.SetFontSize(24)
dpi = self.win.GetDPI()

w, h = vcs.vtk_ui.text.text_dimensions("no descenders", text_property)
w, h = vcs.vtk_ui.text.text_dimensions("no descenders", text_property,
dpi)
if w != 175 or h != 24:
print "no descenders width/height changed"
return

w, h = vcs.vtk_ui.text.text_dimensions("couple good descenders", text_property)
w, h = vcs.vtk_ui.text.text_dimensions("couple good descenders",
text_property, dpi)
if w != 299 or h != 24:
print "couple good descenders width/height changed"
return

w, h = vcs.vtk_ui.text.text_dimensions("This one\nis on\nmultiple lines", text_property)
w, h = vcs.vtk_ui.text.text_dimensions(
"This one\nis on\nmultiple lines", text_property, dpi)
if w != 151 or h != 76:
print "Multi-line width/height changed"
return
Expand Down

0 comments on commit c6392bc

Please sign in to comment.