Lines 264-270
Link Here
|
264 |
vtkPVDataInformation""" |
264 |
vtkPVDataInformation""" |
265 |
if self.SMProxy: |
265 |
if self.SMProxy: |
266 |
return DataInformation( \ |
266 |
return DataInformation( \ |
267 |
self.SMProxy.GetDataInformation(idx, False), \ |
267 |
self.SMProxy.GetDataInformation(idx), \ |
268 |
self.SMProxy, idx) |
268 |
self.SMProxy, idx) |
269 |
|
269 |
|
270 |
class Property(object): |
270 |
class Property(object): |
Lines 330-335
Link Here
|
330 |
val = property[2] |
330 |
val = property[2] |
331 |
property[1:3] = (1, 2) |
331 |
property[1:3] = (1, 2) |
332 |
""" |
332 |
""" |
|
|
333 |
def ConvertValue(self, value): |
334 |
"""Converts value to type suitable for vtSM.Property::SetElement()""" |
335 |
if self.SMProperty.IsA("vtkSMIntVectorProperty") and \ |
336 |
self.SMProperty.GetDomain("enum") and type(value) == str: |
337 |
domain = self.SMProperty.GetDomain("enum") |
338 |
if domain.HasEntryText(value): |
339 |
return domain.GetEntryValueForText(value) |
340 |
return value |
341 |
|
333 |
|
342 |
|
334 |
def __len__(self): |
343 |
def __len__(self): |
335 |
"""Returns the number of elements.""" |
344 |
"""Returns the number of elements.""" |
Lines 344-350
Link Here
|
344 |
|
353 |
|
345 |
def __setitem__(self, idx, value): |
354 |
def __setitem__(self, idx, value): |
346 |
"""Given an index and a value, sets an element.""" |
355 |
"""Given an index and a value, sets an element.""" |
347 |
self.SMProperty.SetElement(idx, value) |
356 |
self.SMProperty.SetElement(idx, self.ConvertValue(value)) |
348 |
self._UpdateProperty() |
357 |
self._UpdateProperty() |
349 |
|
358 |
|
350 |
def __getslice__(self, min, max): |
359 |
def __getslice__(self, min, max): |
Lines 362-368
Link Here
|
362 |
if min < 0 or min > len(self) or max < 0 or max > len(self): |
371 |
if min < 0 or min > len(self) or max < 0 or max > len(self): |
363 |
raise exceptions.IndexError |
372 |
raise exceptions.IndexError |
364 |
for i in range(min, max): |
373 |
for i in range(min, max): |
365 |
self.SMProperty.SetElement(i, values[i-min]) |
374 |
self.SMProperty.SetElement(i, self.ConvertValue(values[i-min])) |
366 |
self._UpdateProperty() |
375 |
self._UpdateProperty() |
367 |
|
376 |
|
368 |
def __getattr__(self, name): |
377 |
def __getattr__(self, name): |
Lines 386-392
Link Here
|
386 |
not isinstance(values, list): |
395 |
not isinstance(values, list): |
387 |
values = (values,) |
396 |
values = (values,) |
388 |
for i in range(len(values)): |
397 |
for i in range(len(values)): |
389 |
self.SMProperty.SetElement(i, values[i]) |
398 |
self.SMProperty.SetElement(i, self.ConvertValue(values[i])) |
390 |
self._UpdateProperty() |
399 |
self._UpdateProperty() |
391 |
|
400 |
|
392 |
def Clear(self): |
401 |
def Clear(self): |
Lines 604-614
Link Here
|
604 |
self.Idx = idx |
613 |
self.Idx = idx |
605 |
|
614 |
|
606 |
def Update(self): |
615 |
def Update(self): |
607 |
"""Update the data information if necessary. Note that this |
616 |
"""****Deprecated**** There is no reason anymore to use this method |
|
|
617 |
explicitly, it is called automatically when one gets any value from the |
618 |
data information object. |
619 |
Update the data information if necessary. Note that this |
608 |
does not cause execution of the underlying object. In certain |
620 |
does not cause execution of the underlying object. In certain |
609 |
cases, you may have to call UpdatePipeline() on the proxy.""" |
621 |
cases, you may have to call UpdatePipeline() on the proxy.""" |
610 |
if self.Proxy: |
622 |
if self.Proxy: |
611 |
self.Proxy.GetDataInformation(self.Idx, False) |
623 |
self.Proxy.GetDataInformation(self.Idx) |
612 |
|
624 |
|
613 |
def GetDataSetType(self): |
625 |
def GetDataSetType(self): |
614 |
"""Returns the dataset type as defined in vtkDataObjectTypes.""" |
626 |
"""Returns the dataset type as defined in vtkDataObjectTypes.""" |
Lines 1105-1125
Link Here
|
1105 |
if not connection: |
1117 |
if not connection: |
1106 |
raise exceptions.RuntimeError, "Cannot load state without a connection" |
1118 |
raise exceptions.RuntimeError, "Cannot load state without a connection" |
1107 |
loader = vtkSMPQStateLoader() |
1119 |
loader = vtkSMPQStateLoader() |
1108 |
rvname = vtkSMRenderViewProxy.GetSuggestedRenderViewType(connection.ID) |
1120 |
pm = ProxyManager() |
1109 |
if rvname: |
1121 |
pm.LoadState(filename, ActiveConnection.ID, loader) |
1110 |
loader.SetRenderViewXMLName(rvname) |
1122 |
views = GetRenderViews() |
1111 |
pm = ProxyManager() |
1123 |
for view in views: |
1112 |
pm.LoadState(filename, ActiveConnection.ID, loader) |
1124 |
# Make sure that the client window size matches the |
1113 |
views = GetRenderViews() |
1125 |
# ViewSize property. In paraview, the GUI takes care |
1114 |
for view in views: |
1126 |
# of this. |
1115 |
# Make sure that the client window size matches the |
1127 |
if view.GetClassName() == "vtkSMIceTDesktopRenderViewProxy": |
1116 |
# ViewSize property. In paraview, the GUI takes care |
1128 |
view.GetRenderWindow().SetSize(view.ViewSize[0], \ |
1117 |
# of this. |
1129 |
view.ViewSize[1]) |
1118 |
if view.GetClassName() == "vtkSMIceTDesktopRenderViewProxy": |
|
|
1119 |
view.GetRenderWindow().SetSize(view.ViewSize[0], \ |
1120 |
view.ViewSize[1]) |
1121 |
else: |
1122 |
raise exceptions.RuntimeError, "Could not load state because no appropriate render view was found." |
1123 |
|
1130 |
|
1124 |
def Connect(ds_host=None, ds_port=11111, rs_host=None, rs_port=11111): |
1131 |
def Connect(ds_host=None, ds_port=11111, rs_host=None, rs_port=11111): |
1125 |
""" |
1132 |
""" |
Lines 1137-1142
Link Here
|
1137 |
render server on rs_host: rs_port. |
1144 |
render server on rs_host: rs_port. |
1138 |
""" |
1145 |
""" |
1139 |
global ActiveConnection |
1146 |
global ActiveConnection |
|
|
1147 |
global fromGUI |
1148 |
if fromGUI: |
1149 |
raise exceptions.RuntimeError, "Cannot create a connection through python. Use the GUI to setup the connection." |
1140 |
if ds_host == None: |
1150 |
if ds_host == None: |
1141 |
connectionId = _connectSelf() |
1151 |
connectionId = _connectSelf() |
1142 |
elif rs_host == None: |
1152 |
elif rs_host == None: |
Lines 1159-1164
Link Here
|
1159 |
The optional port specified the port to listen to. |
1169 |
The optional port specified the port to listen to. |
1160 |
""" |
1170 |
""" |
1161 |
global ActiveConnection |
1171 |
global ActiveConnection |
|
|
1172 |
global fromGUI |
1173 |
if fromGUI: |
1174 |
raise exceptions.RuntimeError, "Cannot create a connection through python. Use the GUI to setup the connection." |
1162 |
connectionId = _connectServer("Reverse connection", port, True) |
1175 |
connectionId = _connectServer("Reverse connection", port, True) |
1163 |
if not ActiveConnection: |
1176 |
if not ActiveConnection: |
1164 |
ActiveConnection = connectionId |
1177 |
ActiveConnection = connectionId |
Lines 1168-1173
Link Here
|
1168 |
"""Disconnects the connection. Make sure to clear the proxy manager |
1181 |
"""Disconnects the connection. Make sure to clear the proxy manager |
1169 |
first.""" |
1182 |
first.""" |
1170 |
global ActiveConnection |
1183 |
global ActiveConnection |
|
|
1184 |
global fromGUI |
1185 |
if fromGUI: |
1186 |
raise exceptions.RuntimeError, "Cannot disconnect through python. Use the GUI to disconnect." |
1171 |
if not connection or connection == ActiveConnection: |
1187 |
if not connection or connection == ActiveConnection: |
1172 |
connection = ActiveConnection |
1188 |
connection = ActiveConnection |
1173 |
ActiveConnection = None |
1189 |
ActiveConnection = None |
Lines 1231-1238
Link Here
|
1231 |
if not connection: |
1247 |
if not connection: |
1232 |
raise exceptions.RuntimeError, "Cannot create render window without connection." |
1248 |
raise exceptions.RuntimeError, "Cannot create render window without connection." |
1233 |
pxm = ProxyManager() |
1249 |
pxm = ProxyManager() |
1234 |
proxy_xml_name = vtkSMRenderViewProxy.GetSuggestedRenderViewType(\ |
1250 |
prototype = pxm.GetPrototypeProxy("views", "RenderView") |
1235 |
connection.ID) |
1251 |
|
|
|
1252 |
proxy_xml_name = prototype.GetSuggestedViewType(connection.ID) |
1236 |
ren_module = None |
1253 |
ren_module = None |
1237 |
if proxy_xml_name: |
1254 |
if proxy_xml_name: |
1238 |
ren_module = CreateProxy("views", proxy_xml_name, connection) |
1255 |
ren_module = CreateProxy("views", proxy_xml_name, connection) |
Lines 1305-1311
Link Here
|
1305 |
updateModules() |
1322 |
updateModules() |
1306 |
|
1323 |
|
1307 |
|
1324 |
|
1308 |
def Fetch(input, arg1=None, arg2=None): |
1325 |
def Fetch(input, arg1=None, arg2=None, idx=0): |
1309 |
""" |
1326 |
""" |
1310 |
A convenience method that moves data from the server to the client, |
1327 |
A convenience method that moves data from the server to the client, |
1311 |
optionally performing some operation on the data as it moves. |
1328 |
optionally performing some operation on the data as it moves. |
Lines 1331-1361
Link Here
|
1331 |
applied pre-gather and arg2 will be applied post-gather. In parallel |
1348 |
applied pre-gather and arg2 will be applied post-gather. In parallel |
1332 |
runs the algorithm will be run on each processor to make intermediate |
1349 |
runs the algorithm will be run on each processor to make intermediate |
1333 |
results and then again on the root processor over all of the |
1350 |
results and then again on the root processor over all of the |
1334 |
intermediate results to create a global result. """ |
1351 |
intermediate results to create a global result. |
|
|
1352 |
|
1353 |
Optional argument idx is used to specify the output port number to fetch the |
1354 |
data from. Default is port 0. |
1355 |
""" |
1335 |
|
1356 |
|
1336 |
import types |
1357 |
import types |
1337 |
|
1358 |
|
1338 |
#create the pipeline that reduces and transmits the data |
1359 |
#create the pipeline that reduces and transmits the data |
1339 |
gvd = rendering.ClientDeliveryRepresentationBase() |
1360 |
gvd = rendering.ClientDeliveryRepresentationBase() |
1340 |
gvd.AddInput(input, "DONTCARE") |
1361 |
gvd.AddInput(0, input, idx, "DONTCARE") |
1341 |
|
1362 |
|
1342 |
if arg1 == None: |
1363 |
if arg1 == None: |
1343 |
print "getting appended" |
1364 |
print "getting appended" |
1344 |
|
1365 |
|
1345 |
cdinfo = input.GetDataInformation().GetCompositeDataInformation() |
1366 |
cdinfo = input.GetDataInformation(idx).GetCompositeDataInformation() |
1346 |
if cdinfo.GetDataIsComposite(): |
1367 |
if cdinfo.GetDataIsComposite(): |
1347 |
print "use composite data append" |
1368 |
print "use composite data append" |
1348 |
gvd.SetReductionType(5) |
1369 |
gvd.SetReductionType(5) |
1349 |
|
1370 |
|
1350 |
elif input.GetDataInformation().GetDataClassName() == "vtkPolyData": |
1371 |
elif input.GetDataInformation(idx).GetDataClassName() == "vtkPolyData": |
1351 |
print "use append poly data filter" |
1372 |
print "use append poly data filter" |
1352 |
gvd.SetReductionType(1) |
1373 |
gvd.SetReductionType(1) |
1353 |
|
1374 |
|
1354 |
elif input.GetDataInformation().GetDataClassName() == "vtkRectilinearGrid": |
1375 |
elif input.GetDataInformation(idx).GetDataClassName() == "vtkRectilinearGrid": |
1355 |
print "use append rectilinear grid filter" |
1376 |
print "use append rectilinear grid filter" |
1356 |
gvd.SetReductionType(4) |
1377 |
gvd.SetReductionType(4) |
1357 |
|
1378 |
|
1358 |
elif input.GetDataInformation().IsA("vtkDataSet"): |
1379 |
elif input.GetDataInformation(idx).IsA("vtkDataSet"): |
1359 |
print "use unstructured append filter" |
1380 |
print "use unstructured append filter" |
1360 |
gvd.SetReductionType(2) |
1381 |
gvd.SetReductionType(2) |
1361 |
|
1382 |
|
Lines 1625-1630
Link Here
|
1625 |
mdl.__dict__[pname] = cobj |
1646 |
mdl.__dict__[pname] = cobj |
1626 |
return mdl |
1647 |
return mdl |
1627 |
|
1648 |
|
|
|
1649 |
|
1650 |
def __determineGroup(proxy): |
1651 |
"""Internal method""" |
1652 |
if not proxy: |
1653 |
return None |
1654 |
xmlgroup = proxy.GetXMLGroup() |
1655 |
xmlname = proxy.GetXMLName() |
1656 |
if xmlgroup == "sources": |
1657 |
return "sources" |
1658 |
elif xmlgroup == "filters": |
1659 |
return "sources" |
1660 |
elif xmlgroup == "views": |
1661 |
return "views" |
1662 |
elif xmlgroup == "representations": |
1663 |
if xmlname == "ScalarBarWidgetRepresentation": |
1664 |
return "scalar_bars" |
1665 |
return "representations"; |
1666 |
elif xmlgroup == "lookup_tables": |
1667 |
return "lookup_tables" |
1668 |
return None |
1669 |
|
1670 |
__nameCounter = 0 |
1671 |
def __determineName(proxy, group): |
1672 |
global __nameCounter |
1673 |
__nameCounter += 1 |
1674 |
return "%s%d" % (proxy.GetXMLName(), __nameCounter) |
1675 |
|
1676 |
def __getName(proxy, group): |
1677 |
pxm = ProxyManager() |
1678 |
if isinstance(proxy, Proxy): |
1679 |
proxy = proxy.SMProxy |
1680 |
return pxm.GetProxyName(group, proxy) |
1681 |
|
1682 |
def Register(proxy, **extraArgs): |
1683 |
"""Registers a proxy with the proxy manager. If no 'registrationGroup' is |
1684 |
specified, then the group is inferred from the type of the proxy. |
1685 |
'registrationName' may be specified to register with a particular name |
1686 |
otherwise a default name will be created.""" |
1687 |
# TODO: handle duplicate registration |
1688 |
if "registrationGroup" in extraArgs: |
1689 |
registrationGroup = extraArgs["registrationGroup"] |
1690 |
else: |
1691 |
registrationGroup = __determineGroup(proxy) |
1692 |
|
1693 |
if "registrationName" in extraArgs: |
1694 |
registrationName = extraArgs["registrationName"] |
1695 |
else: |
1696 |
registrationName = __determineName(proxy, registrationGroup) |
1697 |
if registrationGroup and registrationName: |
1698 |
pxm = ProxyManager() |
1699 |
pxm.RegisterProxy(registrationGroup, registrationName, proxy) |
1700 |
else: |
1701 |
raise exceptions.RuntimeError, "Registeration error." |
1702 |
return (registrationGroup, registrationName); |
1703 |
|
1704 |
def UnRegister(proxy, **extraArgs): |
1705 |
"""UnRegisters proxies registered using Register().""" |
1706 |
if "registrationGroup" in extraArgs: |
1707 |
registrationGroup = extraArgs["registrationGroup"] |
1708 |
else: |
1709 |
registrationGroup = __determineGroup(proxy) |
1710 |
|
1711 |
if "registrationName" in extraArgs: |
1712 |
registrationName = extraArgs["registrationName"] |
1713 |
else: |
1714 |
registrationName = __getName(proxy, registrationGroup) |
1715 |
|
1716 |
if registrationGroup and registrationName: |
1717 |
pxm = ProxyManager() |
1718 |
pxm.UnRegisterProxy(registrationGroup, registrationName, proxy) |
1719 |
else: |
1720 |
raise exceptions.RuntimeError, "UnRegisteration error." |
1721 |
return (registrationGroup, registrationName); |
1722 |
|
1628 |
def demo1(): |
1723 |
def demo1(): |
1629 |
"""This simple demonstration creates a sphere, renders it and delivers |
1724 |
"""This simple demonstration creates a sphere, renders it and delivers |
1630 |
it to the client using Fetch. It returns a tuple of (data, render |
1725 |
it to the client using Fetch. It returns a tuple of (data, render |