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 @@
# based GUI for VTK-Python.
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 \
vtkTkRenderWindowInteractor
import string
......@@ -48,7 +54,7 @@ for family in ("Arial", "Courier", "Times"):
face_name = family
if len(attribs):
face_name = face_name + "(" + \
string.join(attribs, ",") + ")"
",".join(attribs) + ")"
mapper.SetInput(face_name + ": " + default_text)
tprop = mapper.GetTextProperty()
......@@ -64,10 +70,10 @@ for family in ("Arial", "Courier", "Times"):
ren.AddActor(actor)
# Now setup the Tkinter GUI.
# Now setup the tkinter GUI.
# Create the root window.
root = Tkinter.Tk()
root = tkinter.Tk()
# vtkTkRenderWindowInteractor is a Tk widget that we can render into.
# It has a GetRenderWindow method that returns a vtkRenderWindow.
......@@ -106,7 +112,7 @@ def set_font_size(sz):
# the command option to the name of a Python function. Whenever the
# slider value changes this function will be called, enabling us to
# 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,
orient='horizontal', label="Font size:",
command=set_font_size)
......@@ -133,5 +139,5 @@ root.protocol("WM_DELETE_WINDOW", quit)
renWin.Render()
vtkw.Start()
# start the Tkinter event loop.
# start the tkinter event loop.
root.mainloop()
......@@ -3,6 +3,7 @@
# This example demonstrates cell picking using vtkCellPicker. It
# displays the results of picking using a vtkTextMapper.
from __future__ import print_function
import vtk
# create a sphere source, mapper, and actor
......@@ -45,7 +46,7 @@ picker = vtk.vtkCellPicker()
# Create a Python function to create the text for the text mapper used
# to display the results of picking.
def annotatePick(object, event):
print "pick"
print("pick")
global picker, textActor, textMapper
if picker.GetCellId() < 0:
textActor.VisibilityOff()
......
......@@ -38,7 +38,7 @@ def parseFile():
line = file.readline()
numPts = int(getNumberFromLine(line)[0])
numLines = (numPts - 1)/8
numLines = (numPts - 1)//8
# Get the data object's field data and allocate
# room for 4, fields
fieldData = dos.GetOutput().GetFieldData()
......
......@@ -17,7 +17,13 @@
# the associated widget's reslice interpolation mode
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 \
vtkTkRenderWindowInteractor
from vtk.util.misc import vtkGetDataRoot
......@@ -245,17 +251,19 @@ def SetSlice(sl):
###
# Now actually create the GUI
root = Tkinter.Tk()
root = tkinter.Tk()
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.
def quit(obj=root):
obj.quit()
# Popup menu
popm = Tkinter.Menu(top, tearoff=0)
mode = Tkinter.IntVar()
popm = tkinter.Menu(top, tearoff=0)
mode = tkinter.IntVar()
mode.set(1)
popm.add_radiobutton(label="nearest", variable=mode, value=0,
command=SetInterpolation)
......@@ -264,20 +272,20 @@ popm.add_radiobutton(label="linear", variable=mode, value=1,
popm.add_radiobutton(label="cubic", variable=mode, value=2,
command=SetInterpolation)
display_frame = Tkinter.Frame(top)
display_frame = tkinter.Frame(top)
display_frame.pack(side="top", anchor="n", fill="both", expand="false")
# Buttons
ctrl_buttons = Tkinter.Frame(top)
ctrl_buttons = tkinter.Frame(top)
ctrl_buttons.pack(side="top", anchor="n", fill="both", expand="false")
quit_button = Tkinter.Button(ctrl_buttons, text="Quit", command=quit)
capture_button = Tkinter.Button(ctrl_buttons, text="Tif",
quit_button = tkinter.Button(ctrl_buttons, text="Quit", command=quit)
capture_button = tkinter.Button(ctrl_buttons, text="Tif",
command=CaptureImage)
x_button = Tkinter.Button(ctrl_buttons, text="x", command=AlignXaxis)
y_button = Tkinter.Button(ctrl_buttons, text="y", command=AlignYaxis)
z_button = Tkinter.Button(ctrl_buttons, text="z", command=AlignZaxis)
x_button = tkinter.Button(ctrl_buttons, text="x", command=AlignXaxis)
y_button = tkinter.Button(ctrl_buttons, text="y", command=AlignYaxis)
z_button = tkinter.Button(ctrl_buttons, text="z", command=AlignZaxis)
x_button.bind("<Button-3>", lambda e: buttonEvent(e, 0))
y_button.bind("<Button-3>", lambda e: buttonEvent(e, 1))
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):
# 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",
fill="both", expand="false")
......@@ -298,9 +306,9 @@ for i in (render_widget, display_frame):
i.pack(side="top", anchor="n",fill="both", expand="false")
# 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 = Tkinter.Scale(top, from_=zMin, to=zMax, orient="horizontal",
slice = tkinter.Scale(top, from_=zMin, to=zMax, orient="horizontal",
command=SetSlice,variable=slice_number,
label="Slice")
slice.pack(fill="x", expand="false")
......@@ -331,5 +339,5 @@ iact.Initialize()
renWin.Render()
iact.Start()
# Start Tkinter event loop
# Start tkinter event loop
root.mainloop()
#!/usr/bin/env python
import vtk
from vtk import *
import Tkinter
from Tkinter import *
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.vtkLoadPythonTkWidgets
import vtk.tk.vtkTkImageViewerWidget
......@@ -13,7 +21,7 @@ from vtk.util.misc import *
class SampleViewer:
def __init__ ( self ):
self.Tk = Tk = Tkinter.Tk();
self.Tk = Tk = tkinter.Tk();
Tk.title ( 'Python Version of vtkImageDataToTkPhoto' );
# Image pipeline
......
#!/usr/bin/env python
############################################################
from __future__ import print_function
from vtk import *
from vtk.util.misc import vtkGetDataRoot
############################################################
......@@ -19,7 +20,7 @@ interactor.SetRenderWindow( window )
# Retrieve data root
VTK_DATA_ROOT = vtkGetDataRoot()
print VTK_DATA_ROOT
print(VTK_DATA_ROOT)
# Read from AVS UCD data in binary form
reader = vtkAVSucdReader()
reader.SetFileName( VTK_DATA_ROOT + "/Data/UCD2D/UCD_00005.inp" )
......@@ -93,7 +94,7 @@ interface.UseAllBlocksOn()
interface.Update()
# Create mappers and actors for surface rendering of all reconstructed interfaces
interfaceIterator = vtkCompositeDataIterator()
interfaceIterator = vtkDataObjectTreeIterator()
interfaceIterator.SetDataSet( interface.GetOutput() )
interfaceIterator.VisitOnlyLeavesOn()
interfaceIterator.SkipEmptyNodesOn()
......@@ -102,7 +103,7 @@ interfaceIterator.GoToFirstItem()
while ( interfaceIterator.IsDoneWithTraversal() == 0 ):
idx = interfaceIterator.GetCurrentFlatIndex()
# 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.SetInputData( interfaceIterator.GetCurrentDataObject() )
interfaceIterator.GoToNextItem()
......
......@@ -5,7 +5,7 @@
# result back to VTK.
# VTK must be built with VTK_USE_MATLAB_MEX turned on for this example to work!
from __future__ import print_function
from vtk import *
import math
......@@ -32,8 +32,8 @@ if __name__ == "__main__":
result = menginterface.GetVtkDataArray("y")
# 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()):
t = result.GetTuple1(i)
print'result[%d] = %6.4f' % (i,t)
print('result[%d] = %6.4f' % (i,t))
......@@ -5,7 +5,7 @@
# back to VTK.
# VTK must be built with VTK_USE_GNU_R turned on for this example to work!
from __future__ import print_function
from vtk import *
import math
......@@ -41,12 +41,12 @@ if __name__ == "__main__":
bdarray = rinterface.AssignRVariableToVTKDataArray("d")
# 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()):
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.
print "\n\nOutput of R interpreter\n\n"
print Routput_buffer
print("\n\nOutput of R interpreter\n\n")
print(Routput_buffer)
#!/usr/bin/env python
from __future__ import print_function
from vtk import *
import os.path
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Set database parameters
data_dir = "../../../../VTKData/Data/Infovis/SQLite/"
data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
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):
data_dir = "../../../../../../VTKData/Data/Infovis/SQLite/"
data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
sqlite_file = data_dir + "temperatures.db"
databaseToTable = vtkSQLDatabaseTableSource()
databaseToTable.SetURL("sqlite://" + sqlite_file)
......@@ -16,7 +19,7 @@ databaseToTable.SetURL("sqlite://" + sqlite_file)
databaseToTable.SetQuery("select * from main_tbl where CompId==2")
# 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.AddInputConnection( databaseToTable.GetOutputPort() )
ds1.AddColumn("Temp1")
......@@ -31,13 +34,13 @@ ds1.Update()
dStats1 = ds1.GetOutputDataObject( 1 )
dPrimary1 = dStats1.GetBlock( 0 )
dPrimary1.Dump( 15 )
print
print()
# Pull the second data set from the database
databaseToTable.SetQuery("select * from main_tbl where CompId==3")
# 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.AddInputConnection( databaseToTable.GetOutputPort() )
ds2.AddColumn("Temp1")
......@@ -52,10 +55,10 @@ ds2.Update()
dStats2 = ds2.GetOutputDataObject( 1 )
dPrimary2 = dStats2.GetBlock( 0 )
dPrimary2.Dump( 15 )
print
print()
# 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.AddItem( dStats1 )
collection.AddItem( dStats2 )
......@@ -64,10 +67,10 @@ aggregated = vtkMultiBlockDataSet()
ds.Aggregate( collection, aggregated )
dPrimary = aggregated.GetBlock( 0 )
dPrimary.Dump( 15 )
print
print()
# 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.SetLearnOption( 0 )
ds.SetDeriveOption( 1 )
......@@ -77,13 +80,13 @@ ds.Update()
dStats = ds.GetOutputDataObject( 1 )
dDerived = dStats.GetBlock( 1 )
dDerived.Dump( 15 )
print
print()
# Pull entire data set from the database
databaseToTable.SetQuery("select * from main_tbl")
# 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.AddInputConnection( databaseToTable.GetOutputPort() )
ds0.AddColumn("Temp1")
......@@ -100,4 +103,4 @@ dPrimary0 = dStats0.GetBlock( 0 )
dPrimary0.Dump( 15 )
dDerived0 = dStats0.GetBlock( 1 )
dDerived0.Dump( 15 )
print
print()
#!/usr/bin/env python
from vtk import *
import os.path
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Open database
data_dir = "../../../../VTKData/Data/Infovis/SQLite/"
data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
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"
database = vtkSQLDatabase.CreateFromURL("sqlite://" + sqlite_file)
database.Open("")
......
#!/usr/bin/env python
from __future__ import print_function
from vtk import *
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):
data_dir = "../../../../../VTKData/Data/Infovis/SQLite/"
data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
sqlite_file = data_dir + "SmallEmailTest.db"
database = vtkSQLDatabase.CreateFromURL("sqlite://" + sqlite_file)
......@@ -19,7 +22,7 @@ queryToTable.Update()
T = queryToTable.GetOutput()
print "Query Results:"
print("Query Results:")
T.Dump(12)
database.FastDelete()
......
#!/usr/bin/env python
from vtk import *
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):
data_dir = "../../../../../VTKData/Data/Infovis/SQLite/"
data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
if not os.path.exists(data_dir):
data_dir = "../../../../../../VTKData/Data/Infovis/SQLite/"
sqlite_file = data_dir + "SmallEmailTest.db"
......
#!/usr/bin/env python
from vtk import *
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):
data_dir = "../../../../../VTKData/Data/Infovis/SQLite/"
data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
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"
# Construct a graph from database tables (yes very tricky)
......
#!/usr/bin/env python
from __future__ import print_function
from vtk import *
csv_source = vtkDelimitedTextReader()
......@@ -10,5 +11,5 @@ csv_source.Update()
T = csv_source.GetOutput()
print "Table loaded from CSV file:"
print("Table loaded from CSV file:")
T.Dump(10)
......@@ -2,6 +2,7 @@
"""
Just a demo script to test out the DIMACS reader/writer function
"""
from __future__ import print_function
import time
from vtk import *
......@@ -14,17 +15,17 @@ source.SetUseEdgeProbability(True)
source.AllowParallelEdgesOff()
source.Update()
print "Original graph:"
print "\tnum_verts =", source.GetOutput().GetNumberOfVertices()
print "\tnum_edges =", source.GetOutput().GetNumberOfEdges()
print ""
print("Original graph:")
print("\tnum_verts =", source.GetOutput().GetNumberOfVertices())
print("\tnum_edges =", source.GetOutput().GetNumberOfEdges())
print("")
# write the graph to a file
writer = vtkDIMACSGraphWriter()
writer.AddInputConnection(source.GetOutputPort())
writer.SetFileName("graph.gr")
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/>
time.sleep(1)
......@@ -33,11 +34,11 @@ time.sleep(1)
reader = vtkDIMACSGraphReader()
reader.SetFileName("graph.gr")
reader.Update()
print "read graph from 'graph.gr'"
print("read graph from 'graph.gr'")
print "Graph from disk:"
print "\tnum_verts =", reader.GetOutput().GetNumberOfVertices()
print "\tnum_edges =", reader.GetOutput().GetNumberOfEdges()
print("Graph from disk:")
print("\tnum_verts =", reader.GetOutput().GetNumberOfVertices())
print("\tnum_edges =", reader.GetOutput().GetNumberOfEdges())
view = vtkGraphLayoutView()
view.AddRepresentationFromInputConnection(reader.GetOutputPort())
......
......@@ -4,6 +4,7 @@ This file demonstrates the creation of a directed graph using the
Python interface to VTK.
"""
from __future__ import print_function
from vtk import *
#------------------------------------------------------------------------------
......@@ -11,7 +12,7 @@ from vtk import *
#------------------------------------------------------------------------------
if __name__ == "__main__":
print "vtkGraph Example 1: Building a vtkMutableDirectedGraph from scratch."
print("vtkGraph Example 1: Building a vtkMutableDirectedGraph from scratch.")
# Create an empty graph
G = vtkMutableDirectedGraph()
......@@ -54,4 +55,4 @@ if __name__ == "__main__":
view.GetInteractor().Start()
print "vtkGraph Example 1: Finished."
print("vtkGraph Example 1: Finished.")
......@@ -4,6 +4,7 @@ This file demonstrates the creation of a directed graph using the
Python interface to VTK.
"""
from __future__ import print_function
from vtk import *
xdim = 600
......@@ -14,7 +15,7 @@ ydim = 600
#------------------------------------------------------------------------------
if __name__ == "__main__":
print "vtkGraph Example 1: Building a vtkMutableDirectedGraph from scratch."
print("vtkGraph Example 1: Building a vtkMutableDirectedGraph from scratch.")
#----------------------------------------------------------
# Create a graph (see graph1.py for explanations)
......
......@@ -2,6 +2,9 @@
from vtk import *
import os.path
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
def setup_view(link, file, domain1, domain2, hue_range):
reader = vtkDelimitedTextReader()
reader.SetHaveHeaders(True)
......@@ -44,9 +47,9 @@ def setup_view(link, file, domain1, domain2, hue_range):
return view
if __name__ == "__main__":
data_dir = "../../../../VTKData/Data/Infovis/"
data_dir = VTK_DATA_ROOT + "/Data/Infovis/"
if not os.path.exists(data_dir):
data_dir = "../../../../../VTKData/Data/Infovis/"
data_dir = VTK_DATA_ROOT + "/Data/Infovis/"
dt_reader = vtkDelimitedTextReader()
dt_reader.SetHaveHeaders(True)
dt_reader.SetFileName(data_dir + "document-term.csv")
......
#!/usr/bin/env python
from __future__ import print_function
from vtk import *
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 ):
data_dir = "../../../../../VTKData/Data/Infovis/SQLite/"
data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
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"
# Pull the table from the database
......@@ -15,7 +18,7 @@ databaseToTable.SetURL("sqlite://" + sqlite_file)
databaseToTable.SetQuery("select * from main_tbl")
# Calculate descriptive statistics
print "# Calculate descriptive statistics:"
print("# Calculate descriptive statistics:")
ds = vtkDescriptiveStatistics()
ds.AddInputConnection( databaseToTable.GetOutputPort() )
ds.AddColumn("Temp1")
......@@ -27,9 +30,9 @@ dPrimary = dStats.GetBlock( 0 )
dDerived = dStats.GetBlock( 1 )
dPrimary.Dump( 15 )
dDerived.Dump( 15 )
print
print()
print "# Calculate 5-point statistics:"
print("# Calculate 5-point statistics:")
# Calculate 5-point statistics
os = vtkOrderStatistics()
os.AddInputConnection( databaseToTable.GetOutputPort() )
......@@ -40,9 +43,9 @@ os.Update()
oStats = os.GetOutputDataObject( 1 )
oQuantiles = oStats.GetBlock( 2 )
oQuantiles.Dump( 15 )
print
print()
print "# Calculate deciles:"
print("# Calculate deciles:")
# Calculate deciles
os.SetNumberOfIntervals(10)
os.Update()
......@@ -50,9 +53,9 @@ os.Update()
oStats = os.GetOutputDataObject( 1 )
oQuantiles = oStats.GetBlock( 2 )
oQuantiles.Dump( 9 )
print
print()
print "# Calculate correlation and linear regression:"
print("# Calculate correlation and linear regression:")
# Calculate correlation and linear regression
cs = vtkCorrelativeStatistics()
cs.AddInputConnection( databaseToTable.GetOutputPort() )
......@@ -65,10 +68,10 @@ cPrimary = cStats.GetBlock(0)
cDerived = cStats.GetBlock(1)
cPrimary.Dump( 15 )
cDerived.Dump( 15 )
print
print()
print "# Report corresponding deviations (squared Mahalanobis distance):"
print("# Report corresponding deviations (squared Mahalanobis distance):")
# Report corresponding deviations (squared Mahalanobis distance):"
cData = cs.GetOutput(0)
cData.Dump( 15 )
print
print()
#!/usr/bin/env python
from __future__ import print_function
from vtk import *
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):
data_dir = "../../../../../VTKData/Data/Infovis/SQLite/"
data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
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"
# Pull the table from the database
......@@ -18,14 +21,14 @@ databaseToTable.SetQuery("select * from main_tbl")
databaseToTable.Update()
inputTable = databaseToTable.GetOutput()
numRows = inputTable.GetNumberOfRows()
print "Input Table Rows: " , numRows
print("Input Table Rows: " , numRows)
# Divide the table into 4
# Note1: using data specific method
subSize = numRows/4
leftOver = numRows - subSize*4
print "subSize: ", subSize
print "leftOver: ", leftOver
print("subSize: ", subSize)
print("leftOver: ", leftOver)
# Python knows nothing of enumerated types
# 6 = vtkDataObject::FIELD_ASSOCIATION_ROWS
......@@ -59,14 +62,14 @@ threshold.SetMaxValue(vtkVariant(subSize*4+leftOver-1))
threshold.Update()
subTable4 = vtkTable()
subTable4.DeepCopy(threshold.GetOutput())
print "SubTable1 Rows: " , subTable1.GetNumberOfRows()
print "SubTable2 Rows: " , subTable2.GetNumberOfRows()
print "SubTable3 Rows: " , subTable3.GetNumberOfRows()
print "SubTable4 Rows: " , subTable4.GetNumberOfRows()
print("SubTable1 Rows: " , subTable1.GetNumberOfRows())
print("SubTable2 Rows: " , subTable2.GetNumberOfRows())
print("SubTable3 Rows: " , subTable3.GetNumberOfRows())
print("SubTable4 Rows: " , subTable4.GetNumberOfRows())
# Calculate offline(non-streaming) descriptive statistics
print "# Calculate offline descriptive statistics:"
print("# Calculate offline descriptive statistics:")
ds = vtkDescriptiveStatistics()
ds.SetInputConnection(databaseToTable.GetOutputPort())
ds.AddColumn("Temp1")
......@@ -86,7 +89,7 @@ inter.AddColumn("Temp2")
# Calculate online(streaming) descriptive statistics
print "# Calculate online descriptive statistics:"
print("# Calculate online descriptive statistics:")
ss = vtkStreamingStatistics()
ss.SetStatisticsAlgorithm(inter)
ss.SetInputData(subTable1)
......@@ -105,4 +108,4 @@ sStats = ss.GetOutputDataObject( 1 )
sPrimary = sStats.GetBlock( 0 )