Skip to content

Commit

Permalink
Merge pull request #1966 from UV-CDAT/click-info-point-dataset
Browse files Browse the repository at this point in the history
Click info point dataset
  • Loading branch information
danlipsa committed May 20, 2016
2 parents 3d52e6e + 7a59926 commit b5e67ac
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 236 deletions.
197 changes: 94 additions & 103 deletions Packages/vcs/vcs/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,16 @@ def __init__(self, canvas, renWin=None, debug=False, bg=None, geometry=None):
self._renderers = {}
self._plot_keywords = [
'cdmsfile',
'cell_coordinates'
# used to render the continents
'continents_renderer',
'cell_coordinates',
# dataset bounds in lon/lat coordinates
'dataset_bounds',
# This may be smaller than the data viewport. It is used
# if autot is passed
'ratio_autot_viewport',
# used to render the dataset
'dataset_renderer',
# dataset scale: (xScale, yScale)
'dataset_scale',
# used to render the dataset for clicked point info (hardware selection)
'surface_renderer',
# (xScale, yScale) - datasets can be scaled using the window ratio
'surface_scale',
# the same as vcs.utils.getworldcoordinates for now. getworldcoordinates uses
# gm.datawc_... or, if that is not set, it uses data axis margins (without bounds).
'plotting_dataset_bounds',
Expand Down Expand Up @@ -138,99 +136,92 @@ def leftButtonPressEvent(self, obj, event):
d = vcs.elements["display"][dnm]
if d.array[0] is None:
continue
t = vcs.elements["template"][d.template]
gm = vcs.elements[d.g_type][d.g_name]
# for non-linear projection or for meshfill. Meshfill is wrapped at
# VTK level, so vcs calculations do not work.
if gm.projection != "linear" or gm.g_name == 'Gfm':
selector = vtk.vtkHardwareSelector()
datasetRenderer = d.backend['dataset_renderer']
continentsRenderer = d.backend.get('continents_renderer')
dataset = d.backend['vtk_backend_grid']
if (datasetRenderer and dataset):
selector.SetRenderer(datasetRenderer)
selector.SetArea(xy[0], xy[1], xy[0], xy[1])
selector.SetFieldAssociation(vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS)
# We want to be able see information behind continents
if (continentsRenderer):
continentsRenderer.SetDraw(False)
selection = selector.Select()
if (continentsRenderer):
continentsRenderer.SetDraw(True)
if (selection.GetNumberOfNodes() > 0):
selectionNode = selection.GetNode(0)
prop = selectionNode.GetProperties().Get(selectionNode.PROP())
if (prop):
cellIds = prop.GetMapper().GetInput().GetCellData().GetGlobalIds()
if (cellIds):
# scalar value
a = selectionNode.GetSelectionData().GetArray(0)
geometryId = a.GetValue(0)
cellId = cellIds.GetValue(geometryId)
scalars = dataset.GetCellData().GetScalars()
value = scalars.GetValue(cellId)
geoTransform = d.backend['vtk_backend_geo']
if (geoTransform):
geoTransform.Inverse()
# Use the world picker to get world coordinates
# we deform the dataset, so we need to fix the
# world picker using xScale, yScale
xScale, yScale = d.backend['dataset_scale']
worldPicker = vtk.vtkWorldPointPicker()
worldPicker.Pick(xy[0], xy[1], 0, datasetRenderer)
worldPosition = list(worldPicker.GetPickPosition())
if (xScale > yScale):
worldPosition[0] /= (xScale/yScale)
else:
worldPosition[1] /= (yScale/xScale)
lonLat = worldPosition
if (geoTransform):
geoTransform.InternalTransformPoint(worldPosition, lonLat)
geoTransform.Inverse()
st += "Var: %s\n" % d.array[0].id
if (float("inf") not in lonLat):
st += "X=%4.1f\nY=%4.1f\n" % (lonLat[0], lonLat[1])
st += "Value: %g" % value
else:
if t.data.x1 <= x <= t.data.x2 and t.data.y1 <= y <= t.data.y2:
x1, x2, y1, y2 = vcs.utils.getworldcoordinates(gm,
d.array[0].getAxis(-1),
d.array[0].getAxis(-2))

X = (x - t.data.x1) / (t.data.x2 - t.data.x1) * (x2 - x1) + x1
Y = (y - t.data.y1) / (t.data.y2 - t.data.y1) * (y2 - y1) + y1

# Ok we now have the X/Y values we need to figure out the
# indices
try:
I = d.array[0].getAxis(-1).mapInterval((X, X, 'cob'))[0]
try:
J = d.array[
0].getAxis(-2).mapInterval((Y, Y, 'cob'))[0]
# Values at that point
V = d.array[0][..., J, I]
except:
V = d.array[0][..., I]
if isinstance(V, numpy.ndarray):
# Grab the appropriate time slice
if self.canvas.animate.created():
t = self.canvas.animate.frame_num
try:
taxis = V.getTime()
V = V(time=taxis[t % len(taxis)]).flat[0]
except:
V = V.flat[0]
# Use the hardware selector to determine the cell id we clicked on
selector = vtk.vtkHardwareSelector()
surfaceRenderer = d.backend['surface_renderer']
dataset = d.backend['vtk_backend_grid']
if (surfaceRenderer and dataset):
selector.SetRenderer(surfaceRenderer)
selector.SetArea(xy[0], xy[1], xy[0], xy[1])
selector.SetFieldAssociation(vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS)
# We only want to render the surface for selection
renderers = self.renWin.GetRenderers()
renderers.InitTraversal()
while(True):
renderer = renderers.GetNextItem()
if (renderer is None):
break
renderer.SetDraw(False)
surfaceRenderer.SetDraw(True)
selection = selector.Select()
renderers.InitTraversal()
while(True):
renderer = renderers.GetNextItem()
if (renderer is None):
break
renderer.SetDraw(True)
surfaceRenderer.SetDraw(False)
if (selection.GetNumberOfNodes() > 0):
selectionNode = selection.GetNode(0)
prop = selectionNode.GetProperties().Get(selectionNode.PROP())
if (prop):
cellIds = prop.GetMapper().GetInput().GetCellData().GetGlobalIds()
if (cellIds):
st += "Var: %s\n" % d.array[0].id
# cell attribute
a = selectionNode.GetSelectionData().GetArray(0)
geometryId = a.GetValue(0)
cellId = cellIds.GetValue(geometryId)
attributes = dataset.GetCellData().GetScalars()
if (attributes is None):
attributes = dataset.GetCellData().GetVectors()
elementId = cellId

geoTransform = d.backend['vtk_backend_geo']
if (geoTransform):
geoTransform.Inverse()
# Use the world picker to get world coordinates
# we deform the dataset, so we need to fix the
# world picker using xScale, yScale
xScale, yScale = d.backend['surface_scale']
worldPicker = vtk.vtkWorldPointPicker()
worldPicker.Pick(xy[0], xy[1], 0, surfaceRenderer)
worldPosition = list(worldPicker.GetPickPosition())
if (xScale > yScale):
worldPosition[0] /= (xScale/yScale)
else:
V = V.flat[0]
try:
st += "Var: %s\nX[%i] = %4.1f\nY[%i] = %4.1f\nValue: %g" % (
d.array[0].id, I, X, J, Y, V)
except:
st += "Var: %s\nX = %4.1f\nY[%i] = %4.1f\nValue: %g" % (
d.array[0].id, X, I, Y, V)
except:
st += "Var: %s\nX=%g\nY=%g\nValue = N/A" % (
d.array[0].id, X, Y)
worldPosition[1] /= (yScale/xScale)
lonLat = worldPosition
if (attributes is None):
# if point dataset, return the value for the closest point
cell = dataset.GetCell(cellId)
closestPoint = [0, 0, 0]
subId = vtk.mutable(0)
pcoords = [0, 0, 0]
dist2 = vtk.mutable(0)
weights = [0] * cell.GetNumberOfPoints()
cell.EvaluatePosition(worldPosition, closestPoint,
subId, pcoords, dist2, weights)
indexMax = numpy.argmax(weights)
pointId = cell.GetPointId(indexMax)
attributes = dataset.GetPointData().GetScalars()
if (attributes is None):
attributes = dataset.GetPointData().GetVectors()
elementId = pointId
if (geoTransform):
geoTransform.InternalTransformPoint(worldPosition, lonLat)
geoTransform.Inverse()
if (float("inf") not in lonLat):
st += "X=%4.1f\nY=%4.1f\n" % (lonLat[0], lonLat[1])
# get the cell value or the closest point value
if (attributes):
if (attributes.GetNumberOfComponents() > 1):
v = attributes.GetTuple(elementId)
st += "Value: (%g, %g)" % (v[0], v[1])
else:
value = attributes.GetValue(elementId)
st += "Value: %g" % value

if st == "":
return
ren = vtk.vtkRenderer()
Expand Down Expand Up @@ -859,9 +850,9 @@ def renderTemplate(self, tmpl, data, gm, taxis, zaxis, **kargs):
ren = self.createRenderer()
self.renWin.AddRenderer(ren)
self.setLayer(ren, 1)
self._renderers[(None, None, None)] = ren
self._renderers[(None, None, None)] = (ren, 1, 1)
else:
ren = self._renderers[(None, None, None)]
ren, xratio, yratio = self._renderers[(None, None, None)]
tt, to = crdate.name.split(":::")
tt = vcs.elements["texttable"][tt]
to = vcs.elements["textorientation"][to]
Expand Down Expand Up @@ -896,9 +887,9 @@ def renderTemplate(self, tmpl, data, gm, taxis, zaxis, **kargs):
ren = self.createRenderer()
self.renWin.AddRenderer(ren)
self.setLayer(ren, 1)
self._renderers[(None, None, None)] = ren
self._renderers[(None, None, None)] = (ren, 1, 1)
else:
ren = self._renderers[(None, None, None)]
ren, xratio, yratio = self._renderers[(None, None, None)]
tt, to = zname.name.split(":::")
tt = vcs.elements["texttable"][tt]
to = vcs.elements["textorientation"][to]
Expand Down
1 change: 1 addition & 0 deletions Packages/vcs/vcs/vcs2vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ def doWrap(Act, wc, wrap=[0., 360], fastClip=True):
if wrap is None:
return Act
Mapper = Act.GetMapper()
Mapper.Update()
data = Mapper.GetInput()
# insure that GLOBALIDS are not removed by the append filter
attributes = data.GetCellData()
Expand Down
3 changes: 0 additions & 3 deletions Packages/vcs/vcs/vcsvtk/boxfillpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ def _plotInternal(self):
geo=self._vtkGeoTransform,
priority=self._template.data.priority,
create_renderer=(dataset_renderer is None))
self._resultDict['dataset_renderer'] = dataset_renderer
self._resultDict['dataset_scale'] = (xScale, yScale)

for act in patternActors:
if self._vtkGeoTransform is None:
Expand Down Expand Up @@ -211,7 +209,6 @@ def _plotInternal(self):
vp, self._template.data.priority,
vtk_backend_grid=self._vtkDataSet,
dataset_bounds=self._vtkDataSetBounds)
self._resultDict['continents_renderer'] = continents_renderer

def _plotInternalBoxfill(self):
"""Implements the logic to render a non-custom boxfill."""
Expand Down
3 changes: 0 additions & 3 deletions Packages/vcs/vcs/vcsvtk/isofillpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ def _plotInternal(self):
geo=self._vtkGeoTransform,
priority=self._template.data.priority,
create_renderer=(dataset_renderer is None))
self._resultDict['dataset_renderer'] = dataset_renderer
self._resultDict['dataset_scale'] = (xScale, yScale)
for act in patternActors:
self._context().fitToViewport(
act, vp,
Expand Down Expand Up @@ -226,4 +224,3 @@ def _plotInternal(self):
vp, self._template.data.priority,
vtk_backend_grid=self._vtkDataSet,
dataset_bounds=self._vtkDataSetBounds)
self._resultDict['continents_renderer'] = continents_renderer
3 changes: 0 additions & 3 deletions Packages/vcs/vcs/vcsvtk/isolinepipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ def _plotInternal(self):
create_renderer=(dataset_renderer is None))

countLevels += len(l)
self._resultDict['dataset_renderer'] = dataset_renderer
self._resultDict['dataset_scale'] = (xScale, yScale)
if len(textprops) > 0:
self._resultDict["vtk_backend_contours_labels_text_properties"] = \
textprops
Expand Down Expand Up @@ -332,4 +330,3 @@ def _plotInternal(self):
vp, self._template.data.priority,
vtk_backend_grid=self._vtkDataSet,
dataset_bounds=self._vtkDataSetBounds)
self._resultDict['continents_renderer'] = continents_renderer
3 changes: 0 additions & 3 deletions Packages/vcs/vcs/vcsvtk/meshfillpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ def _plotInternal(self):
geo=self._vtkGeoTransform,
priority=self._template.data.priority,
create_renderer=(dataset_renderer is None))
self._resultDict['dataset_renderer'] = dataset_renderer
self._resultDict['dataset_scale'] = (xScale, yScale)
for act in self._patternActors:
if self._vtkGeoTransform is None:
# If using geofilter on wireframed does not get wrapped not sure
Expand Down Expand Up @@ -270,7 +268,6 @@ def _plotInternal(self):
vp, self._template.data.priority,
vtk_backend_grid=self._vtkDataSet,
dataset_bounds=self._vtkDataSetBounds)
self._resultDict['continents_renderer'] = continents_renderer

def getPlottingBounds(self):
"""gm.datawc if it is set or dataset_bounds
Expand Down
Loading

0 comments on commit b5e67ac

Please sign in to comment.