Commit a7996f41 authored by Andrew Maclean's avatar Andrew Maclean Committed by David Gobbi

Converting python examples so they also run on Py3k.

parent 3bfe9914
...@@ -5,7 +5,13 @@ ...@@ -5,7 +5,13 @@
# based GUI for VTK-Python. # based GUI for VTK-Python.
import vtk import vtk
import Tkinter import sys
if sys.hexversion < 0x03000000:
# for Python2
import Tkinter as tkinter
else:
# for Python3
import tkinter
from vtk.tk.vtkTkRenderWindowInteractor import \ from vtk.tk.vtkTkRenderWindowInteractor import \
vtkTkRenderWindowInteractor vtkTkRenderWindowInteractor
import string import string
...@@ -48,7 +54,7 @@ for family in ("Arial", "Courier", "Times"): ...@@ -48,7 +54,7 @@ for family in ("Arial", "Courier", "Times"):
face_name = family face_name = family
if len(attribs): if len(attribs):
face_name = face_name + "(" + \ face_name = face_name + "(" + \
string.join(attribs, ",") + ")" ",".join(attribs) + ")"
mapper.SetInput(face_name + ": " + default_text) mapper.SetInput(face_name + ": " + default_text)
tprop = mapper.GetTextProperty() tprop = mapper.GetTextProperty()
...@@ -64,10 +70,10 @@ for family in ("Arial", "Courier", "Times"): ...@@ -64,10 +70,10 @@ for family in ("Arial", "Courier", "Times"):
ren.AddActor(actor) ren.AddActor(actor)
# Now setup the Tkinter GUI. # Now setup the tkinter GUI.
# Create the root window. # Create the root window.
root = Tkinter.Tk() root = tkinter.Tk()
# vtkTkRenderWindowInteractor is a Tk widget that we can render into. # vtkTkRenderWindowInteractor is a Tk widget that we can render into.
# It has a GetRenderWindow method that returns a vtkRenderWindow. # It has a GetRenderWindow method that returns a vtkRenderWindow.
...@@ -106,7 +112,7 @@ def set_font_size(sz): ...@@ -106,7 +112,7 @@ def set_font_size(sz):
# the command option to the name of a Python function. Whenever the # the command option to the name of a Python function. Whenever the
# slider value changes this function will be called, enabling us to # slider value changes this function will be called, enabling us to
# propagate this GUI setting to the corresponding VTK object. # propagate this GUI setting to the corresponding VTK object.
size_slider = Tkinter.Scale(root, from_=min_font_size, size_slider = tkinter.Scale(root, from_=min_font_size,
to=max_font_size, res=1, to=max_font_size, res=1,
orient='horizontal', label="Font size:", orient='horizontal', label="Font size:",
command=set_font_size) command=set_font_size)
...@@ -133,5 +139,5 @@ root.protocol("WM_DELETE_WINDOW", quit) ...@@ -133,5 +139,5 @@ root.protocol("WM_DELETE_WINDOW", quit)
renWin.Render() renWin.Render()
vtkw.Start() vtkw.Start()
# start the Tkinter event loop. # start the tkinter event loop.
root.mainloop() root.mainloop()
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# This example demonstrates cell picking using vtkCellPicker. It # This example demonstrates cell picking using vtkCellPicker. It
# displays the results of picking using a vtkTextMapper. # displays the results of picking using a vtkTextMapper.
from __future__ import print_function
import vtk import vtk
# create a sphere source, mapper, and actor # create a sphere source, mapper, and actor
...@@ -45,7 +46,7 @@ picker = vtk.vtkCellPicker() ...@@ -45,7 +46,7 @@ picker = vtk.vtkCellPicker()
# Create a Python function to create the text for the text mapper used # Create a Python function to create the text for the text mapper used
# to display the results of picking. # to display the results of picking.
def annotatePick(object, event): def annotatePick(object, event):
print "pick" print("pick")
global picker, textActor, textMapper global picker, textActor, textMapper
if picker.GetCellId() < 0: if picker.GetCellId() < 0:
textActor.VisibilityOff() textActor.VisibilityOff()
......
...@@ -38,7 +38,7 @@ def parseFile(): ...@@ -38,7 +38,7 @@ def parseFile():
line = file.readline() line = file.readline()
numPts = int(getNumberFromLine(line)[0]) numPts = int(getNumberFromLine(line)[0])
numLines = (numPts - 1)/8 numLines = (numPts - 1)//8
# Get the data object's field data and allocate # Get the data object's field data and allocate
# room for 4, fields # room for 4, fields
fieldData = dos.GetOutput().GetFieldData() fieldData = dos.GetOutput().GetFieldData()
......
...@@ -17,7 +17,13 @@ ...@@ -17,7 +17,13 @@
# the associated widget's reslice interpolation mode # the associated widget's reslice interpolation mode
import vtk import vtk
import Tkinter import sys
if sys.hexversion < 0x03000000:
# for Python2
import Tkinter as tkinter
else:
# for Python3
import tkinter
from vtk.tk.vtkTkRenderWindowInteractor import \ from vtk.tk.vtkTkRenderWindowInteractor import \
vtkTkRenderWindowInteractor vtkTkRenderWindowInteractor
from vtk.util.misc import vtkGetDataRoot from vtk.util.misc import vtkGetDataRoot
...@@ -245,17 +251,19 @@ def SetSlice(sl): ...@@ -245,17 +251,19 @@ def SetSlice(sl):
### ###
# Now actually create the GUI # Now actually create the GUI
root = Tkinter.Tk() root = tkinter.Tk()
root.withdraw() root.withdraw()
top = Tkinter.Toplevel(root) top = tkinter.Toplevel(root)
# Define what to do when the user explicitly closes a window.
root.protocol("WM_DELETE_WINDOW", quit)
# Define a quit method that exits cleanly. # Define a quit method that exits cleanly.
def quit(obj=root): def quit(obj=root):
obj.quit() obj.quit()
# Popup menu # Popup menu
popm = Tkinter.Menu(top, tearoff=0) popm = tkinter.Menu(top, tearoff=0)
mode = Tkinter.IntVar() mode = tkinter.IntVar()
mode.set(1) mode.set(1)
popm.add_radiobutton(label="nearest", variable=mode, value=0, popm.add_radiobutton(label="nearest", variable=mode, value=0,
command=SetInterpolation) command=SetInterpolation)
...@@ -264,20 +272,20 @@ popm.add_radiobutton(label="linear", variable=mode, value=1, ...@@ -264,20 +272,20 @@ popm.add_radiobutton(label="linear", variable=mode, value=1,
popm.add_radiobutton(label="cubic", variable=mode, value=2, popm.add_radiobutton(label="cubic", variable=mode, value=2,
command=SetInterpolation) command=SetInterpolation)
display_frame = Tkinter.Frame(top) display_frame = tkinter.Frame(top)
display_frame.pack(side="top", anchor="n", fill="both", expand="false") display_frame.pack(side="top", anchor="n", fill="both", expand="false")
# Buttons # Buttons
ctrl_buttons = Tkinter.Frame(top) ctrl_buttons = tkinter.Frame(top)
ctrl_buttons.pack(side="top", anchor="n", fill="both", expand="false") ctrl_buttons.pack(side="top", anchor="n", fill="both", expand="false")
quit_button = Tkinter.Button(ctrl_buttons, text="Quit", command=quit) quit_button = tkinter.Button(ctrl_buttons, text="Quit", command=quit)
capture_button = Tkinter.Button(ctrl_buttons, text="Tif", capture_button = tkinter.Button(ctrl_buttons, text="Tif",
command=CaptureImage) command=CaptureImage)
x_button = Tkinter.Button(ctrl_buttons, text="x", command=AlignXaxis) x_button = tkinter.Button(ctrl_buttons, text="x", command=AlignXaxis)
y_button = Tkinter.Button(ctrl_buttons, text="y", command=AlignYaxis) y_button = tkinter.Button(ctrl_buttons, text="y", command=AlignYaxis)
z_button = Tkinter.Button(ctrl_buttons, text="z", command=AlignZaxis) z_button = tkinter.Button(ctrl_buttons, text="z", command=AlignZaxis)
x_button.bind("<Button-3>", lambda e: buttonEvent(e, 0)) x_button.bind("<Button-3>", lambda e: buttonEvent(e, 0))
y_button.bind("<Button-3>", lambda e: buttonEvent(e, 1)) y_button.bind("<Button-3>", lambda e: buttonEvent(e, 1))
z_button.bind("<Button-3>", lambda e: buttonEvent(e, 2)) z_button.bind("<Button-3>", lambda e: buttonEvent(e, 2))
...@@ -287,7 +295,7 @@ for i in (quit_button, capture_button, x_button, y_button, z_button): ...@@ -287,7 +295,7 @@ for i in (quit_button, capture_button, x_button, y_button, z_button):
# Create the render widget # Create the render widget
renderer_frame = Tkinter.Frame(display_frame) renderer_frame = tkinter.Frame(display_frame)
renderer_frame.pack(padx=3, pady=3,side="left", anchor="n", renderer_frame.pack(padx=3, pady=3,side="left", anchor="n",
fill="both", expand="false") fill="both", expand="false")
...@@ -298,9 +306,9 @@ for i in (render_widget, display_frame): ...@@ -298,9 +306,9 @@ for i in (render_widget, display_frame):
i.pack(side="top", anchor="n",fill="both", expand="false") i.pack(side="top", anchor="n",fill="both", expand="false")
# Add a slice scale to browse the current slice stack # Add a slice scale to browse the current slice stack
slice_number = Tkinter.IntVar() slice_number = tkinter.IntVar()
slice_number.set(current_widget.GetSliceIndex()) slice_number.set(current_widget.GetSliceIndex())
slice = Tkinter.Scale(top, from_=zMin, to=zMax, orient="horizontal", slice = tkinter.Scale(top, from_=zMin, to=zMax, orient="horizontal",
command=SetSlice,variable=slice_number, command=SetSlice,variable=slice_number,
label="Slice") label="Slice")
slice.pack(fill="x", expand="false") slice.pack(fill="x", expand="false")
...@@ -331,5 +339,5 @@ iact.Initialize() ...@@ -331,5 +339,5 @@ iact.Initialize()
renWin.Render() renWin.Render()
iact.Start() iact.Start()
# Start Tkinter event loop # Start tkinter event loop
root.mainloop() root.mainloop()
#!/usr/bin/env python #!/usr/bin/env python
import vtk import vtk
from vtk import * from vtk import *
import Tkinter
from Tkinter import *
import sys, os import sys, os
#import Tkinter
#from Tkinter import *
if sys.hexversion < 0x03000000:
# for Python2
import Tkinter as tkinter
from Tkinter import *
else:
# for Python3
import tkinter
from tkinter import *
import vtk.tk import vtk.tk
import vtk.tk.vtkLoadPythonTkWidgets import vtk.tk.vtkLoadPythonTkWidgets
import vtk.tk.vtkTkImageViewerWidget import vtk.tk.vtkTkImageViewerWidget
...@@ -13,7 +21,7 @@ from vtk.util.misc import * ...@@ -13,7 +21,7 @@ from vtk.util.misc import *
class SampleViewer: class SampleViewer:
def __init__ ( self ): def __init__ ( self ):
self.Tk = Tk = Tkinter.Tk(); self.Tk = Tk = tkinter.Tk();
Tk.title ( 'Python Version of vtkImageDataToTkPhoto' ); Tk.title ( 'Python Version of vtkImageDataToTkPhoto' );
# Image pipeline # Image pipeline
......
#!/usr/bin/env python #!/usr/bin/env python
############################################################ ############################################################
from __future__ import print_function
from vtk import * from vtk import *
from vtk.util.misc import vtkGetDataRoot from vtk.util.misc import vtkGetDataRoot
############################################################ ############################################################
...@@ -19,7 +20,7 @@ interactor.SetRenderWindow( window ) ...@@ -19,7 +20,7 @@ interactor.SetRenderWindow( window )
# Retrieve data root # Retrieve data root
VTK_DATA_ROOT = vtkGetDataRoot() VTK_DATA_ROOT = vtkGetDataRoot()
print VTK_DATA_ROOT print(VTK_DATA_ROOT)
# Read from AVS UCD data in binary form # Read from AVS UCD data in binary form
reader = vtkAVSucdReader() reader = vtkAVSucdReader()
reader.SetFileName( VTK_DATA_ROOT + "/Data/UCD2D/UCD_00005.inp" ) reader.SetFileName( VTK_DATA_ROOT + "/Data/UCD2D/UCD_00005.inp" )
...@@ -93,7 +94,7 @@ interface.UseAllBlocksOn() ...@@ -93,7 +94,7 @@ interface.UseAllBlocksOn()
interface.Update() interface.Update()
# Create mappers and actors for surface rendering of all reconstructed interfaces # Create mappers and actors for surface rendering of all reconstructed interfaces
interfaceIterator = vtkCompositeDataIterator() interfaceIterator = vtkDataObjectTreeIterator()
interfaceIterator.SetDataSet( interface.GetOutput() ) interfaceIterator.SetDataSet( interface.GetOutput() )
interfaceIterator.VisitOnlyLeavesOn() interfaceIterator.VisitOnlyLeavesOn()
interfaceIterator.SkipEmptyNodesOn() interfaceIterator.SkipEmptyNodesOn()
...@@ -102,7 +103,7 @@ interfaceIterator.GoToFirstItem() ...@@ -102,7 +103,7 @@ interfaceIterator.GoToFirstItem()
while ( interfaceIterator.IsDoneWithTraversal() == 0 ): while ( interfaceIterator.IsDoneWithTraversal() == 0 ):
idx = interfaceIterator.GetCurrentFlatIndex() idx = interfaceIterator.GetCurrentFlatIndex()
# Create mapper for leaf node # Create mapper for leaf node
print "Creating mapper and actor for object with flat index", idx print("Creating mapper and actor for object with flat index", idx)
interfaceMapper = vtkDataSetMapper() interfaceMapper = vtkDataSetMapper()
interfaceMapper.SetInputData( interfaceIterator.GetCurrentDataObject() ) interfaceMapper.SetInputData( interfaceIterator.GetCurrentDataObject() )
interfaceIterator.GoToNextItem() interfaceIterator.GoToNextItem()
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# result back to VTK. # result back to VTK.
# VTK must be built with VTK_USE_MATLAB_MEX turned on for this example to work! # VTK must be built with VTK_USE_MATLAB_MEX turned on for this example to work!
from __future__ import print_function
from vtk import * from vtk import *
import math import math
...@@ -32,8 +32,8 @@ if __name__ == "__main__": ...@@ -32,8 +32,8 @@ if __name__ == "__main__":
result = menginterface.GetVtkDataArray("y") result = menginterface.GetVtkDataArray("y")
# Display contents of result, should be all ones. # Display contents of result, should be all ones.
print "\n\nContents of result array copied to VTK from Matlab\n\n" print("\n\nContents of result array copied to VTK from Matlab\n\n")
for i in range(result.GetNumberOfTuples()): for i in range(result.GetNumberOfTuples()):
t = result.GetTuple1(i) t = result.GetTuple1(i)
print'result[%d] = %6.4f' % (i,t) print('result[%d] = %6.4f' % (i,t))
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# back to VTK. # back to VTK.
# VTK must be built with VTK_USE_GNU_R turned on for this example to work! # VTK must be built with VTK_USE_GNU_R turned on for this example to work!
from __future__ import print_function
from vtk import * from vtk import *
import math import math
...@@ -41,12 +41,12 @@ if __name__ == "__main__": ...@@ -41,12 +41,12 @@ if __name__ == "__main__":
bdarray = rinterface.AssignRVariableToVTKDataArray("d") bdarray = rinterface.AssignRVariableToVTKDataArray("d")
# Display the contents of bdarray. # Display the contents of bdarray.
print "\n\nContents of bdarray copied to VTK from R\n\n" print("\n\nContents of bdarray copied to VTK from R\n\n")
for i in range(bdarray.GetNumberOfTuples()): for i in range(bdarray.GetNumberOfTuples()):
t = bdarray.GetTuple2(i) t = bdarray.GetTuple2(i)
print'%6.4f %6.4f' % (t[0], t[1]) print('%6.4f %6.4f' % (t[0], t[1]))
# Display the contents of R output echoed to the terminal. # Display the contents of R output echoed to the terminal.
print "\n\nOutput of R interpreter\n\n" print("\n\nOutput of R interpreter\n\n")
print Routput_buffer print(Routput_buffer)
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function
from vtk import * from vtk import *
import os.path import os.path
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Set database parameters # Set database parameters
data_dir = "../../../../VTKData/Data/Infovis/SQLite/" data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
if not os.path.exists( data_dir): if not os.path.exists( data_dir):
data_dir = "../../../../../VTKData/Data/Infovis/SQLite/" data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
if not os.path.exists( data_dir): if not os.path.exists( data_dir):
data_dir = "../../../../../../VTKData/Data/Infovis/SQLite/" data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
sqlite_file = data_dir + "temperatures.db" sqlite_file = data_dir + "temperatures.db"
databaseToTable = vtkSQLDatabaseTableSource() databaseToTable = vtkSQLDatabaseTableSource()
databaseToTable.SetURL("sqlite://" + sqlite_file) databaseToTable.SetURL("sqlite://" + sqlite_file)
...@@ -16,7 +19,7 @@ databaseToTable.SetURL("sqlite://" + sqlite_file) ...@@ -16,7 +19,7 @@ databaseToTable.SetURL("sqlite://" + sqlite_file)
databaseToTable.SetQuery("select * from main_tbl where CompId==2") databaseToTable.SetQuery("select * from main_tbl where CompId==2")
# Calculate primary descriptive statistics for first batch # Calculate primary descriptive statistics for first batch
print "# Calculate primary model of descriptive statistics for first data set:" print("# Calculate primary model of descriptive statistics for first data set:")
ds1 = vtkDescriptiveStatistics() ds1 = vtkDescriptiveStatistics()
ds1.AddInputConnection( databaseToTable.GetOutputPort() ) ds1.AddInputConnection( databaseToTable.GetOutputPort() )
ds1.AddColumn("Temp1") ds1.AddColumn("Temp1")
...@@ -31,13 +34,13 @@ ds1.Update() ...@@ -31,13 +34,13 @@ ds1.Update()
dStats1 = ds1.GetOutputDataObject( 1 ) dStats1 = ds1.GetOutputDataObject( 1 )
dPrimary1 = dStats1.GetBlock( 0 ) dPrimary1 = dStats1.GetBlock( 0 )
dPrimary1.Dump( 15 ) dPrimary1.Dump( 15 )
print print()
# Pull the second data set from the database # Pull the second data set from the database
databaseToTable.SetQuery("select * from main_tbl where CompId==3") databaseToTable.SetQuery("select * from main_tbl where CompId==3")
# Calculate primary descriptive statistics for second batch # Calculate primary descriptive statistics for second batch
print "# Calculate primary model of descriptive statistics for second data set:" print("# Calculate primary model of descriptive statistics for second data set:")
ds2 = vtkDescriptiveStatistics() ds2 = vtkDescriptiveStatistics()
ds2.AddInputConnection( databaseToTable.GetOutputPort() ) ds2.AddInputConnection( databaseToTable.GetOutputPort() )
ds2.AddColumn("Temp1") ds2.AddColumn("Temp1")
...@@ -52,10 +55,10 @@ ds2.Update() ...@@ -52,10 +55,10 @@ ds2.Update()
dStats2 = ds2.GetOutputDataObject( 1 ) dStats2 = ds2.GetOutputDataObject( 1 )
dPrimary2 = dStats2.GetBlock( 0 ) dPrimary2 = dStats2.GetBlock( 0 )
dPrimary2.Dump( 15 ) dPrimary2.Dump( 15 )
print print()
# Finally aggregate both models to get a new primary model for the whole ensemble # Finally aggregate both models to get a new primary model for the whole ensemble
print "# Aggregate both primary models:" print("# Aggregate both primary models:")
collection = vtkDataObjectCollection() collection = vtkDataObjectCollection()
collection.AddItem( dStats1 ) collection.AddItem( dStats1 )
collection.AddItem( dStats2 ) collection.AddItem( dStats2 )
...@@ -64,10 +67,10 @@ aggregated = vtkMultiBlockDataSet() ...@@ -64,10 +67,10 @@ aggregated = vtkMultiBlockDataSet()
ds.Aggregate( collection, aggregated ) ds.Aggregate( collection, aggregated )
dPrimary = aggregated.GetBlock( 0 ) dPrimary = aggregated.GetBlock( 0 )
dPrimary.Dump( 15 ) dPrimary.Dump( 15 )
print print()
# Calculate derived model for whole ensemble # Calculate derived model for whole ensemble
print "# Now calculating derived statistics for whole ensemble:" print("# Now calculating derived statistics for whole ensemble:")
ds.SetInputData( 2, aggregated ) ds.SetInputData( 2, aggregated )
ds.SetLearnOption( 0 ) ds.SetLearnOption( 0 )
ds.SetDeriveOption( 1 ) ds.SetDeriveOption( 1 )
...@@ -77,13 +80,13 @@ ds.Update() ...@@ -77,13 +80,13 @@ ds.Update()
dStats = ds.GetOutputDataObject( 1 ) dStats = ds.GetOutputDataObject( 1 )
dDerived = dStats.GetBlock( 1 ) dDerived = dStats.GetBlock( 1 )
dDerived.Dump( 15 ) dDerived.Dump( 15 )
print print()
# Pull entire data set from the database # Pull entire data set from the database
databaseToTable.SetQuery("select * from main_tbl") databaseToTable.SetQuery("select * from main_tbl")
# Verify with calculation for whole ensemble at once # Verify with calculation for whole ensemble at once
print "# Finally verifying by directly calculating statistics for whole ensemble:" print("# Finally verifying by directly calculating statistics for whole ensemble:")
ds0 = vtkDescriptiveStatistics() ds0 = vtkDescriptiveStatistics()
ds0.AddInputConnection( databaseToTable.GetOutputPort() ) ds0.AddInputConnection( databaseToTable.GetOutputPort() )
ds0.AddColumn("Temp1") ds0.AddColumn("Temp1")
...@@ -100,4 +103,4 @@ dPrimary0 = dStats0.GetBlock( 0 ) ...@@ -100,4 +103,4 @@ dPrimary0 = dStats0.GetBlock( 0 )
dPrimary0.Dump( 15 ) dPrimary0.Dump( 15 )
dDerived0 = dStats0.GetBlock( 1 ) dDerived0 = dStats0.GetBlock( 1 )
dDerived0.Dump( 15 ) dDerived0.Dump( 15 )
print print()
#!/usr/bin/env python #!/usr/bin/env python
from vtk import * from vtk import *
import os.path import os.path
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Open database # Open database
data_dir = "../../../../VTKData/Data/Infovis/SQLite/" data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
if not os.path.exists(data_dir): if not os.path.exists(data_dir):
data_dir = "../../../../../VTKData/Data/Infovis/SQLite/" data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
sqlite_file = data_dir + "ports_protocols.db" sqlite_file = data_dir + "ports_protocols.db"
database = vtkSQLDatabase.CreateFromURL("sqlite://" + sqlite_file) database = vtkSQLDatabase.CreateFromURL("sqlite://" + sqlite_file)
database.Open("") database.Open("")
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function
from vtk import * from vtk import *
import os.path import os.path
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
data_dir = "../../../../VTKData/Data/Infovis/SQLite/" data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
if not os.path.exists(data_dir): if not os.path.exists(data_dir):
data_dir = "../../../../../VTKData/Data/Infovis/SQLite/" data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
sqlite_file = data_dir + "SmallEmailTest.db" sqlite_file = data_dir + "SmallEmailTest.db"
database = vtkSQLDatabase.CreateFromURL("sqlite://" + sqlite_file) database = vtkSQLDatabase.CreateFromURL("sqlite://" + sqlite_file)
...@@ -19,7 +22,7 @@ queryToTable.Update() ...@@ -19,7 +22,7 @@ queryToTable.Update()
T = queryToTable.GetOutput() T = queryToTable.GetOutput()
print "Query Results:" print("Query Results:")
T.Dump(12) T.Dump(12)
database.FastDelete() database.FastDelete()
......
#!/usr/bin/env python #!/usr/bin/env python
from vtk import * from vtk import *
import os.path import os.path
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
data_dir = "../../../../VTKData/Data/Infovis/SQLite/" data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
if not os.path.exists(data_dir): if not os.path.exists(data_dir):
data_dir = "../../../../../VTKData/Data/Infovis/SQLite/" data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
if not os.path.exists(data_dir): if not os.path.exists(data_dir):
data_dir = "../../../../../../VTKData/Data/Infovis/SQLite/" data_dir = "../../../../../../VTKData/Data/Infovis/SQLite/"
sqlite_file = data_dir + "SmallEmailTest.db" sqlite_file = data_dir + "SmallEmailTest.db"
......
#!/usr/bin/env python #!/usr/bin/env python
from vtk import * from vtk import *
import os.path import os.path
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
data_dir = "../../../../VTKData/Data/Infovis/SQLite/" data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
if not os.path.exists(data_dir): if not os.path.exists(data_dir):
data_dir = "../../../../../VTKData/Data/Infovis/SQLite/" data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
if not os.path.exists(data_dir): if not os.path.exists(data_dir):
data_dir = "../../../../../../VTKData/Data/Infovis/SQLite/" data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
sqlite_file = data_dir + "SmallEmailTest.db" sqlite_file = data_dir + "SmallEmailTest.db"
# Construct a graph from database tables (yes very tricky) # Construct a graph from database tables (yes very tricky)
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function
from vtk import * from vtk import *
csv_source = vtkDelimitedTextReader() csv_source = vtkDelimitedTextReader()
...@@ -10,5 +11,5 @@ csv_source.Update() ...@@ -10,5 +11,5 @@ csv_source.Update()
T = csv_source.GetOutput() T = csv_source.GetOutput()
print "Table loaded from CSV file:" print("Table loaded from CSV file:")
T.Dump(10) T.Dump(10)
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
""" """
Just a demo script to test out the DIMACS reader/writer function Just a demo script to test out the DIMACS reader/writer function
""" """
from __future__ import print_function
import time import time
from vtk import * from vtk import *
...@@ -14,17 +15,17 @@ source.SetUseEdgeProbability(True) ...@@ -14,17 +15,17 @@ source.SetUseEdgeProbability(True)
source.AllowParallelEdgesOff() source.AllowParallelEdgesOff()
source.Update() source.Update()
print "Original graph:" print("Original graph:")
print "\tnum_verts =", source.GetOutput().GetNumberOfVertices() print("\tnum_verts =", source.GetOutput().GetNumberOfVertices())
print "\tnum_edges =", source.GetOutput().GetNumberOfEdges() print("\tnum_edges =", source.GetOutput().GetNumberOfEdges())
print "" print("")
# write the graph to a file # write the graph to a file
writer = vtkDIMACSGraphWriter() writer = vtkDIMACSGraphWriter()
writer.AddInputConnection(source.GetOutputPort()) writer.AddInputConnection(source.GetOutputPort())
writer.SetFileName("graph.gr") writer.SetFileName("graph.gr")
writer.Update() writer.Update()
print "wrote graph to 'graph.gr'" print("wrote graph to 'graph.gr'")
# let's pause a second to let the disk catch up <shrug/> # let's pause a second to let the disk catch up <shrug/>
time.sleep(1) time.sleep(1)
...@@ -33,11 +34,11 @@ time.sleep(1) ...@@ -33,11 +34,11 @@ time.sleep(1)
reader = vtkDIMACSGraphReader() reader = vtkDIMACSGraphReader()