本文整理汇总了Python中vtk.vtkContextView函数的典型用法代码示例。如果您正苦于以下问题:Python vtkContextView函数的具体用法?Python vtkContextView怎么用?Python vtkContextView使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkContextView函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testLinePlot
def testLinePlot(self):
"Test if line plots can be built with python"
# Set up a 2D scene, add an XY chart to it
view = vtk.vtkContextView()
view.GetRenderer().SetBackground(1.0,1.0,1.0)
view.GetRenderWindow().SetSize(400,300)
chart = vtk.vtkChartXY()
view.GetScene().AddItem(chart)
# Create a table with some points in it
table = vtk.vtkTable()
arrX = vtk.vtkFloatArray()
arrX.SetName("X Axis")
arrC = vtk.vtkFloatArray()
arrC.SetName("Cosine")
arrS = vtk.vtkFloatArray()
arrS.SetName("Sine")
arrS2 = vtk.vtkFloatArray()
arrS2.SetName("Sine2")
numPoints = 69
inc = 7.5 / (numPoints - 1)
for i in range(0,numPoints):
arrX.InsertNextValue(i*inc)
arrC.InsertNextValue(math.cos(i * inc) + 0.0)
arrS.InsertNextValue(math.sin(i * inc) + 0.0)
arrS2.InsertNextValue(math.sin(i * inc) + 0.5)
table.AddColumn(arrX)
table.AddColumn(arrC)
table.AddColumn(arrS)
table.AddColumn(arrS2)
# Now add the line plots with appropriate colors
line = chart.AddPlot(0)
line.SetInput(table,0,1)
line.SetColor(0,255,0,255)
line.SetWidth(1.0)
line = chart.AddPlot(0)
line.SetInput(table,0,2)
line.SetColor(255,0,0,255);
line.SetWidth(5.0)
line = chart.AddPlot(0)
line.SetInput(table,0,3)
line.SetColor(0,0,255,255);
line.SetWidth(4.0)
view.GetRenderWindow().SetMultiSamples(0)
img_file = "TestLinePlot.png"
vtk.test.Testing.compareImage(view.GetRenderWindow(),vtk.test.Testing.getAbsImagePath(img_file),threshold=25)
vtk.test.Testing.interact()
开发者ID:BobObara,项目名称:VTK,代码行数:60,代码来源:TestLinePlot.py
示例2: TestColorTransferFunction
def TestColorTransferFunction(int , char):
# Set up a 2D scene, add an XY chart to it
view = vtk.vtkContextView()
view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
view.GetRenderWindow().SetSize(400, 300)
chart = vtk.vtkChartXY()
chart.SetTitle('Chart')
view.GetScene().AddItem(chart)
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.AddHSVSegment(50.,0.,1.,1.,85.,0.3333,1.,1.)
colorTransferFunction.AddHSVSegment(85.,0.3333,1.,1.,170.,0.6666,1.,1.)
colorTransferFunction.AddHSVSegment(170.,0.6666,1.,1.,200.,0.,1.,1.)
colorTransferFunction.Build()
colorTransferItem = vtk.vtkColorTransferFunctionItem()
colorTransferItem.SetColorTransferFunction(colorTransferFunction)
chart.AddPlot(colorTransferItem)
controlPointsItem = vtk.vtkColorTransferControlPointsItem()
controlPointsItem.SetColorTransferFunction(colorTransferFunction)
controlPointsItem.SetUserBounds(0., 255., 0., 1.)
chart.AddPlot(controlPointsItem)
# Finally render the scene and compare the image to a reference image
view.GetRenderWindow().SetMultiSamples(1)
if view.GetContext().GetDevice().IsA( "vtkOpenGLContextDevice2D") :
view.GetInteractor().Initialize()
view.GetInteractor().Start()
else:
print 'GL version 2 or higher is required.'
return EXIT_SUCCESS
开发者ID:behollis,项目名称:DBSViewer,代码行数:35,代码来源:TestColorTransferFunction.py
示例3: __init__
def __init__(self, parent=None):
QCellWidget.__init__(self, parent)
centralLayout = QtGui.QVBoxLayout()
self.setLayout(centralLayout)
centralLayout.setMargin(0)
centralLayout.setSpacing(0)
self.view = vtk.vtkContextView()
self.widget = QVTKRenderWindowInteractor(self,
rw=self.view.GetRenderWindow(),
iren=self.view.GetInteractor()
)
self.chart = vtk.vtkChartParallelCoordinates()
self.view.GetScene().AddItem(self.chart)
self.layout().addWidget(self.widget)
# Create a annotation link to access selection in parallel coordinates view
self.annotationLink = vtk.vtkAnnotationLink()
# If you don't set the FieldType explicitly it ends up as UNKNOWN (as of 21 Feb 2010)
# See vtkSelectionNode doc for field and content type enum values
self.annotationLink.GetCurrentSelection().GetNode(0).SetFieldType(1) # Point
self.annotationLink.GetCurrentSelection().GetNode(0).SetContentType(4) # Indices
# Connect the annotation link to the parallel coordinates representation
self.chart.SetAnnotationLink(self.annotationLink)
self.annotationLink.AddObserver("AnnotationChangedEvent", self.selectionCallback)
开发者ID:imclab,项目名称:vistrails,代码行数:28,代码来源:plots.py
示例4: generateParallelCoordinatesPlot
def generateParallelCoordinatesPlot( self ):
input = self.inputModule().getOutput()
ptData = input.GetPointData()
narrays = ptData.GetNumberOfArrays()
arrays = []
# Create a table with some points in it...
table = vtk.vtkTable()
for iArray in range( narrays ):
table.AddColumn( ptData.GetArray( iArray ) )
# Set up a 2D scene, add an XY chart to it
view = vtk.vtkContextView()
# view.SetRenderer( self.renderer )
# view.SetRenderWindow( self.renderer.GetRenderWindow() )
view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
view.GetRenderWindow().SetSize(600,300)
plot = vtk.vtkPlotParallelCoordinates()
plot.SetInput(table)
view.GetScene().AddItem(plot)
view.ResetCamera()
view.Render()
# Start interaction event loop
view.GetInteractor().Start()
开发者ID:imclab,项目名称:vistrails,代码行数:26,代码来源:ParallelCoordinatesModule.py
示例5: addPlot
def addPlot(self,_plotName,_style="Lines"): # called directly from Steppable; add a (possibly more than one) plot to a plot window
self.plotWindowInterfaceMutex.lock()
# self.plotWindowMutex.lock()
# return
# print MODULENAME,' addPlot(): _plotName= ',_plotName
# import pdb; pdb.set_trace()
# self.plotData[_plotName] = [array([],dtype=double),array([],dtype=double),False] # 'array': from PyQt4.Qwt5.anynumpy import *
self.chart = vtk.vtkChartXY()
# self.chart.GetAxis(vtk.vtkAxis.LEFT).SetLogScale(True)
# self.chart.GetAxis(vtk.vtkAxis.BOTTOM).SetLogScale(True)
# self.numCharts += 1
self.plotData[_plotName] = [self.chart]
self.view = vtk.vtkContextView()
self.ren = self.view.GetRenderer()
# self.renWin = self.qvtkWidget.GetRenderWindow()
self.renWin = self.pW.GetRenderWindow()
self.renWin.AddRenderer(self.ren)
# Create a table with some points in it
self.table = vtk.vtkTable()
self.arrX = vtk.vtkFloatArray()
self.arrX.SetName("xarray")
self.arrC = vtk.vtkFloatArray()
self.arrC.SetName("yarray")
numPoints = 5
numPoints = 15
inc = 7.5 / (numPoints - 1)
# for i in range(0,numPoints):
# self.arrX.InsertNextValue(i*inc)
# self.arrC.InsertNextValue(math.cos(i * inc) + 0.0)
# self.arrX.InsertNextValue(0.0)
# self.arrC.InsertNextValue(0.0)
# self.arrX.InsertNextValue(0.1)
# self.arrC.InsertNextValue(0.1)
self.table.AddColumn(self.arrX)
self.table.AddColumn(self.arrC)
# Now add the line plots with appropriate colors
self.line = self.chart.AddPlot(0)
self.line.SetInput(self.table,0,1)
self.line.SetColor(0,0,255,255)
self.line.SetWidth(1.0)
self.view.GetRenderer().SetBackground([0.6,0.6,0.1])
self.view.GetRenderer().SetBackground([1.0,1.0,1.0])
self.view.GetScene().AddItem(self.chart)
self.plotWindowInterfaceMutex.unlock()
开发者ID:CompuCell3D,项目名称:CompuCell3D,代码行数:60,代码来源:PlotManagerVTK.py
示例6: initialize
def initialize(self, VTKWebApp, args):
dataid = args.id
treedata = getDBdata(dataid)
VTKWebApp.tree1 = treedata["tree1"]
VTKWebApp.tree2 = treedata["tree2"]
VTKWebApp.table = dataid+ ".csv"
# Create default pipeline (Only once for all the session)
if not VTKWebApp.view:
# read the trees
treeReader1 = vtk.vtkNewickTreeReader()
treeReader1.SetReadFromInputString(1)
treeReader1.SetInputString(VTKWebApp.tree1)
treeReader1.Update()
tree1 = treeReader1.GetOutput()
treeReader2 = vtk.vtkNewickTreeReader()
treeReader2.SetReadFromInputString(1)
treeReader2.SetInputString(VTKWebApp.tree2)
treeReader2.Update()
tree2 = treeReader2.GetOutput()
# read the table
tableReader = vtk.vtkDelimitedTextReader()
tableReader.SetFileName(VTKWebApp.table)
tableReader.SetHaveHeaders(True)
tableReader.DetectNumericColumnsOn()
tableReader.ForceDoubleOn()
tableReader.Update()
table = tableReader.GetOutput()
# setup the tanglegram
tanglegram = vtk.vtkTanglegramItem()
tanglegram.SetTree1(tree1);
tanglegram.SetTree2(tree2);
tanglegram.SetTable(table);
tanglegram.SetTree1Label("tree1");
tanglegram.SetTree2Label("tree2");
# setup the window
view = vtk.vtkContextView()
view.GetRenderer().SetBackground(1,1,1)
view.GetRenderWindow().SetSize(800,600)
iren = view.GetInteractor()
iren.SetRenderWindow(view.GetRenderWindow())
transformItem = vtk.vtkContextTransform()
transformItem.AddItem(tanglegram)
transformItem.SetInteractive(1)
view.GetScene().AddItem(transformItem)
view.GetRenderWindow().SetMultiSamples(0)
iren.Initialize()
view.GetRenderWindow().Render()
# VTK Web application specific
VTKWebApp.view = view.GetRenderWindow()
self.Application.GetObjectIdMap().SetActiveObject("VIEW", view.GetRenderWindow())
开发者ID:chinchliff,项目名称:ArborWebApps,代码行数:60,代码来源:vtk_tanglegram.py
示例7: create_widgets
def create_widgets(self):
# transfer function control
self.qtVtkWidget = DBSTransferFunctionWindowInteractor(self, \
app=self.parent() )
self._contextView = vtk.vtkContextView()
self._contextView.SetRenderWindow(self.qtVtkWidget.GetRenderWindow())
开发者ID:behollis,项目名称:DBSViewer,代码行数:8,代码来源:dbsControlDialogs.py
示例8: testBarGraph
def testBarGraph(self):
"Test if bar graphs can be built with python"
# Set up a 2D scene, add an XY chart to it
view = vtk.vtkContextView()
view.GetRenderer().SetBackground(1.0,1.0,1.0)
view.GetRenderWindow().SetSize(400,300)
chart = vtk.vtkChartXY()
view.GetScene().AddItem(chart)
# Create a table with some points in it
table = vtk.vtkTable()
arrMonth = vtk.vtkIntArray()
arrMonth.SetName("Month")
arr2008 = vtk.vtkIntArray()
arr2008.SetName("2008")
arr2009 = vtk.vtkIntArray()
arr2009.SetName("2009")
arr2010 = vtk.vtkIntArray()
arr2010.SetName("2010")
numMonths = 12
for i in range(0,numMonths):
arrMonth.InsertNextValue(i + 1)
arr2008.InsertNextValue(data_2008[i])
arr2009.InsertNextValue(data_2009[i])
arr2010.InsertNextValue(data_2010[i])
table.AddColumn(arrMonth)
table.AddColumn(arr2008)
table.AddColumn(arr2009)
table.AddColumn(arr2010)
# Now add the line plots with appropriate colors
line = chart.AddPlot(2)
line.SetInput(table,0,1)
line.SetColor(0,255,0,255)
line = chart.AddPlot(2)
line.SetInput(table,0,2)
line.SetColor(255,0,0,255);
line = chart.AddPlot(2)
line.SetInput(table,0,3)
line.SetColor(0,0,255,255);
view.GetRenderWindow().SetMultiSamples(0)
view.GetRenderWindow().Render()
img_file = "TestBarGraph.png"
vtk.test.Testing.compareImage(view.GetRenderWindow(),vtk.test.Testing.getAbsImagePath(img_file),threshold=25)
vtk.test.Testing.interact()
开发者ID:kramarb,项目名称:VTK,代码行数:57,代码来源:TestBarGraph.py
示例9: __init__
def __init__(self, data_source, input_link=None, highlight_link=None):
"""Parallel coordinates view constructor needs a valid DataSource plus
and external annotation link (from the icicle view).
"""
self.ds = data_source
self.input_link = None
if input_link is not None:
self.SetInputAnnotationLink(input_link)
# Set up a 2D scene, add an XY chart to it
self.view = vtk.vtkContextView()
self.view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
self.view.GetRenderWindow().SetSize(600,300)
self.chart = vtkvtg.vtkMyChartParallelCoordinates()
self.highlight_link = None
if highlight_link is not None:
self.SetHighlightAnnotationLink(highlight_link)
# Create a annotation link to access selection in parallel coordinates view
self.link = vtk.vtkAnnotationLink()
# If you don't set the FieldType explicitly it ends up as UNKNOWN (as of 21 Feb 2010)
# See vtkSelectionNode doc for field and content type enum values
self.link.GetCurrentSelection().GetNode(0).SetFieldType(1) # Point
# The chart seems to force INDEX selection, so I'm using vtkConvertSelection below to get
# out PedigreeIds...
self.link.GetCurrentSelection().GetNode(0).SetContentType(4) # 2 = PedigreeIds, 4 = Indices
# Connect the annotation link to the parallel coordinates representation
self.chart.SetAnnotationLink(self.link)
# Set up callback for ID -> Pedigree ID conversion & copy to output link
self.link.AddObserver("AnnotationChangedEvent", self.PCoordsSelectionCallback)
# Set up output annotation link which will carry pedigree ids to image flow view
# Type and field will be set during conversion to pedigree ids in PCoordsSelectionCallback
self.output_link = vtk.vtkAnnotationLink()
self.view.GetScene().AddItem(self.chart)
# self.view.ResetCamera()
# self.view.Render()
# Set default scale range to show: 'all', 'coarse', 'fine'
# TODO: Should check the menu to see which is checked so default is
# set by GUI
self.scale_range = 'coarse'
# Want to keep track of whether the node coming in on the input_link
# is new or not
self.input_link_idx = 0
# Flag for whether to color by 'category_ids'
# TODO: Should check the menu to see which is checked so default is
# set by GUI
self.SetColorByArray("None")
开发者ID:emonson,项目名称:MultiScaleSVD,代码行数:57,代码来源:pcoords_chart.py
示例10: testPythonItem
def testPythonItem(self):
width = 400
height = 400
view = vtk.vtkContextView()
renWin = view.GetRenderWindow()
renWin.SetSize(width, height)
area = vtk.vtkInteractiveArea()
view.GetScene().AddItem(area)
drawAreaBounds = vtk.vtkRectd(0.0, 0.0, 1.0, 1.0)
vp = [0.05, 0.95, 0.05, 0.95]
screenGeometry = vtk.vtkRecti(int(vp[0] * width),
int(vp[2] * height),
int((vp[1] - vp[0]) * width),
int((vp[3] - vp[2]) * height))
item = vtk.vtkPythonItem()
item.SetPythonObject(CustomPythonItem(buildPolyData()))
item.SetVisible(True)
area.GetDrawAreaItem().AddItem(item)
area.SetDrawAreaBounds(drawAreaBounds)
area.SetGeometry(screenGeometry)
area.SetFillViewport(False)
area.SetShowGrid(False)
axisLeft = area.GetAxis(vtk.vtkAxis.LEFT)
axisRight = area.GetAxis(vtk.vtkAxis.RIGHT)
axisBottom = area.GetAxis(vtk.vtkAxis.BOTTOM)
axisTop = area.GetAxis(vtk.vtkAxis.TOP)
axisTop.SetVisible(False)
axisRight.SetVisible(False)
axisLeft.SetVisible(False)
axisBottom.SetVisible(False)
axisTop.SetMargins(0, 0)
axisRight.SetMargins(0, 0)
axisLeft.SetMargins(0, 0)
axisBottom.SetMargins(0, 0)
renWin.Render()
# Create a vtkTesting object
rtTester = vtk.vtkTesting()
rtTester.SetRenderWindow(renWin)
for arg in sys.argv[1:]:
rtTester.AddArgument(arg)
# Perform the image comparison test and print out the result.
result = rtTester.RegressionTest(0.0)
if result == 0:
raise Exception("TestPythonItem failed.")
开发者ID:ElsevierSoftwareX,项目名称:SOFTX-D-15-00004,代码行数:56,代码来源:testPythonItem.py
示例11: __init__
def __init__(self):
self._rendererScene = vtk.vtkRenderer()
self._rendererScene.SetBackground(self.COLOR_BG)
self._renderWindowScene = vtk.vtkRenderWindow()
self._renderWindowScene.AddRenderer(self._rendererScene)
self._renderWindowInteractor = vtk.vtkRenderWindowInteractor()
self._renderWindowInteractor.SetRenderWindow(self._renderWindowScene)
#self._interactorStyle = vtk.vtkInteractorStyleUnicam()
self._interactorStyle = self.KeyPressInteractorStyle()
self._interactorStyle.SetCamera(self._rendererScene.GetActiveCamera())
self._interactorStyle.SetRenderer(self._rendererScene)
self._interactorStyle.SetRenderWindow(self._renderWindowScene)
self._contextViewPlotCurv = vtk.vtkContextView()
self._contextViewPlotCurv.GetRenderer().SetBackground(self.COLOR_BG_PLOT)
self._contextInteractorStyleCurv = self.KeyPressContextInteractorStyle()
self._contextInteractorStyleCurv.SetRenderWindow(self._contextViewPlotCurv.GetRenderWindow())
self._chartXYCurv = vtk.vtkChartXY()
self._contextViewPlotCurv.GetScene().AddItem(self._chartXYCurv)
self._chartXYCurv.SetShowLegend(True)
self._chartXYCurv.GetAxis(vtk.vtkAxis.LEFT).SetTitle("")
self._chartXYCurv.GetAxis(vtk.vtkAxis.BOTTOM).SetTitle("")
self._contextViewPlotTors = vtk.vtkContextView()
self._contextViewPlotTors.GetRenderer().SetBackground(self.COLOR_BG_PLOT)
self._contextInteractorStyleTors = self.KeyPressContextInteractorStyle()
self._contextInteractorStyleTors.SetRenderWindow(self._contextViewPlotTors.GetRenderWindow())
self._chartXYTors = vtk.vtkChartXY()
self._contextViewPlotTors.GetScene().AddItem(self._chartXYTors)
self._chartXYTors.SetShowLegend(True)
self._chartXYTors.GetAxis(vtk.vtkAxis.LEFT).SetTitle("")
self._chartXYTors.GetAxis(vtk.vtkAxis.BOTTOM).SetTitle("")
self._textActor = vtk.vtkTextActor()
self._textActor.GetTextProperty().SetColor(self.COLOR_LENGTH)
self._addedBSpline = False
开发者ID:trianam,项目名称:voropath,代码行数:42,代码来源:plotter.py
示例12: initialize
def initialize(self):
global renderer, renderWindow, renderWindowInteractor, cone, mapper, actor
# Bring used components
self.registerVtkWebProtocol(protocols.vtkWebMouseHandler())
self.registerVtkWebProtocol(protocols.vtkWebViewPort())
self.registerVtkWebProtocol(protocols.vtkWebViewPortImageDelivery())
self.registerVtkWebProtocol(protocols.vtkWebViewPortGeometryDelivery())
# Update authentication key to use
self.updateSecret(_PhylogeneticTree.authKey)
# Create default pipeline (Only once for all the session)
if not _PhylogeneticTree.view:
# read in a tree
treeReader = vtk.vtkNewickTreeReader()
treeReader.SetFileName(_PhylogeneticTree.treeFilePath)
treeReader.Update()
reader = treeReader.GetOutput()
# read in a table
tableReader = vtk.vtkDelimitedTextReader()
tableReader.SetFileName(_PhylogeneticTree.csvFilePath)
tableReader.SetHaveHeaders(True)
tableReader.DetectNumericColumnsOn()
tableReader.Update()
table = tableReader.GetOutput()
# play with the heatmap vis
treeHeatmapItem = vtk.vtkTreeHeatmapItem()
treeHeatmapItem.SetTree(reader);
treeHeatmapItem.SetTable(table);
# setup the window
view = vtk.vtkContextView()
view.GetRenderer().SetBackground(1,1,1)
view.GetRenderWindow().SetSize(800,600)
iren = view.GetInteractor()
iren.SetRenderWindow(view.GetRenderWindow())
transformItem = vtk.vtkContextTransform()
transformItem.AddItem(treeHeatmapItem)
transformItem.SetInteractive(1)
view.GetScene().AddItem(transformItem)
view.GetRenderWindow().SetMultiSamples(0)
iren.Initialize()
view.GetRenderWindow().Render()
# VTK Web application specific
_PhylogeneticTree.view = view.GetRenderWindow()
self.Application.GetObjectIdMap().SetActiveObject("VIEW", view.GetRenderWindow())
开发者ID:Andy-Sun,项目名称:VTK,代码行数:54,代码来源:vtk_web_phylogenetic_tree.py
示例13: generateParallelCoordinatesChart
def generateParallelCoordinatesChart( self ):
input = self.inputModule().getOutput()
ptData = input.GetPointData()
narrays = ptData.GetNumberOfArrays()
arrays = []
# Create a table with some points in it...
table = vtk.vtkTable()
for iArray in range( narrays ):
table.AddColumn( ptData.GetArray( iArray ) )
# Set up a 2D scene, add an XY chart to it
view = vtk.vtkContextView()
# view.SetRenderer( self.renderer )
# view.SetRenderWindow( self.renderer.GetRenderWindow() )
view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
view.GetRenderWindow().SetSize(600,300)
chart = vtk.vtkChartParallelCoordinates()
brush = vtk.vtkBrush()
brush.SetColorF (0.1,0.1,0.1)
chart.SetBackgroundBrush(brush)
# Create a annotation link to access selection in parallel coordinates view
annotationLink = vtk.vtkAnnotationLink()
# If you don't set the FieldType explicitly it ends up as UNKNOWN (as of 21 Feb 2010)
# See vtkSelectionNode doc for field and content type enum values
annotationLink.GetCurrentSelection().GetNode(0).SetFieldType(1) # Point
annotationLink.GetCurrentSelection().GetNode(0).SetContentType(4) # Indices
# Connect the annotation link to the parallel coordinates representation
chart.SetAnnotationLink(annotationLink)
view.GetScene().AddItem(chart)
chart.GetPlot(0).SetInput(table)
def selectionCallback(caller, event):
annSel = annotationLink.GetCurrentSelection()
if annSel.GetNumberOfNodes() > 0:
idxArr = annSel.GetNode(0).GetSelectionList()
if idxArr.GetNumberOfTuples() > 0:
print VN.vtk_to_numpy(idxArr)
# Set up callback to update 3d render window when selections are changed in
# parallel coordinates view
annotationLink.AddObserver("AnnotationChangedEvent", selectionCallback)
# view.ResetCamera()
# view.Render()
# view.GetInteractor().Start()
return view
开发者ID:imclab,项目名称:vistrails,代码行数:52,代码来源:ParallelCoordinatesModule.py
示例14: initialize
def initialize(self, VTKWebApp, args):
VTKWebApp.treeFilePath = args.tree
VTKWebApp.csvFilePath = args.table
# Create default pipeline (Only once for all the session)
if not VTKWebApp.view:
# read in a tree
treeReader = vtk.vtkNewickTreeReader()
treeReader.SetFileName(VTKWebApp.treeFilePath)
treeReader.Update()
reader = treeReader.GetOutput()
# read in a table
tableReader = vtk.vtkDelimitedTextReader()
tableReader.SetFileName(VTKWebApp.csvFilePath)
tableReader.SetHaveHeaders(1)
tableReader.DetectNumericColumnsOn()
tableReader.Update()
table = tableReader.GetOutput()
# play with the heatmap vis
treeHeatmapItem = vtk.vtkTreeHeatmapItem()
treeHeatmapItem.SetTree(reader)
treeHeatmapItem.SetTable(table)
# setup the window
view = vtk.vtkContextView()
view.GetRenderer().SetBackground(1, 1, 1)
view.GetRenderWindow().SetSize(800, 600)
iren = view.GetInteractor()
iren.SetRenderWindow(view.GetRenderWindow())
transformItem = vtk.vtkContextTransform()
transformItem.AddItem(treeHeatmapItem)
transformItem.SetInteractive(1)
view.GetScene().AddItem(transformItem)
view.GetRenderWindow().SetMultiSamples(0)
iren.Initialize()
view.GetRenderWindow().Render()
# VTK Web application specific
VTKWebApp.view = view.GetRenderWindow()
self.Application.GetObjectIdMap().SetActiveObject("VIEW", view.GetRenderWindow())
开发者ID:hafen,项目名称:tangelo,代码行数:46,代码来源:vtkweb_tree.py
示例15: testLinePlot
def testLinePlot(self):
"Test if colored parallel coordinates plots can be built with python"
# Set up a 2D scene, add a PC chart to it
view = vtk.vtkContextView()
view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
view.GetRenderWindow().SetSize(600,300)
chart = vtk.vtkChartParallelCoordinates()
view.GetScene().AddItem(chart)
# Create a table with some points in it
arrX = vtk.vtkFloatArray()
arrX.SetName("XAxis")
arrC = vtk.vtkFloatArray()
arrC.SetName("Cosine")
arrS = vtk.vtkFloatArray()
arrS.SetName("Sine")
arrS2 = vtk.vtkFloatArray()
arrS2.SetName("Tan")
numPoints = 200
inc = 7.5 / (numPoints-1)
for i in range(numPoints):
arrX.InsertNextValue(i * inc)
arrC.InsertNextValue(math.cos(i * inc) + 0.0)
arrS.InsertNextValue(math.sin(i * inc) + 0.0)
arrS2.InsertNextValue(math.tan(i * inc) + 0.5)
table = vtk.vtkTable()
table.AddColumn(arrX)
table.AddColumn(arrC)
table.AddColumn(arrS)
table.AddColumn(arrS2)
# Create blue to gray to red lookup table
lut = vtk.vtkLookupTable()
lutNum = 256
lut.SetNumberOfTableValues(lutNum)
lut.Build()
ctf = vtk.vtkColorTransferFunction()
ctf.SetColorSpaceToDiverging()
cl = []
# Variant of Colorbrewer RdBu 5
cl.append([float(cc)/255.0 for cc in [202, 0, 32]])
cl.append([float(cc)/255.0 for cc in [244, 165, 130]])
cl.append([float(cc)/255.0 for cc in [140, 140, 140]])
cl.append([float(cc)/255.0 for cc in [146, 197, 222]])
cl.append([float(cc)/255.0 for cc in [5, 113, 176]])
vv = [float(xx)/float(len(cl)-1) for xx in range(len(cl))]
vv.reverse()
for pt,color in zip(vv,cl):
ctf.AddRGBPoint(pt, color[0], color[1], color[2])
for ii,ss in enumerate([float(xx)/float(lutNum) for xx in range(lutNum)]):
cc = ctf.GetColor(ss)
lut.SetTableValue(ii,cc[0],cc[1],cc[2],1.0)
lut.SetAlpha(0.25)
lut.SetRange(-1, 1)
chart.GetPlot(0).SetInputData(table)
chart.GetPlot(0).SetScalarVisibility(1)
chart.GetPlot(0).SetLookupTable(lut)
chart.GetPlot(0).SelectColorArray("Cosine")
view.GetRenderWindow().SetMultiSamples(0)
view.GetRenderWindow().Render()
img_file = "TestParallelCoordinatesColors.png"
vtk.test.Testing.compareImage(view.GetRenderWindow(),vtk.test.Testing.getAbsImagePath(img_file),threshold=25)
vtk.test.Testing.interact()
开发者ID:timkrentz,项目名称:SunTracker,代码行数:77,代码来源:TestParallelCoordinatesColors.py
示例16: __init__
def __init__(self, parent = None):
QtGui.QMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.renWinList = []
# data_file = askopenfilename()
data_file = '/Users/emonson/Data/Fodava/EMoGWDataSets/mnist1_5c_20100324.mat'
# self.openFilesDefaultPath = QtCore.QDir.homePath()
# data_file = QtGui.QFileDialog.getOpenFileName(self,
# "Load Saved Matlab File",
# self.openFilesDefaultPath,
# "All Files (*);;Matlab Files (*.mat)")
# DataSource loads .mat file and can generate data from it for other views
self.ds = DataSource(str(data_file))
# All view classes have access to an instance of that data source for internal queries
# Note that the only view which will pull and display data right away is the icicle view
# the other views need to be able to initialize without any data and only pull and show
# upon the first AnnotationChanged event...
# View #0 -- Icicle View
# Set up a 2D scene, add an XY chart to it
self.chartView = vtk.vtkContextView()
self.chartView.GetRenderer().SetBackground(1.0, 1.0, 1.0)
self.renWinList.append(self.chartView.GetRenderWindow())
self.chart = vtkvtg.vtkMyChartXY()
self.chartView.GetScene().AddItem(self.chart)
# View #1 -- AxisImageView
self.axisView = vtk.vtkContextView()
self.axisView.GetRenderer().SetBackground(1.0, 1.0, 1.0)
self.renWinList.append(self.axisView.GetRenderWindow())
self.ai = vtkvtg.vtkAxisImageItem()
self.axisView.GetScene().AddItem(self.ai)
# Set up all the render windows in the GUI
self.ui.setupUi(self, self.renWinList)
# Now need to get all the interactors working properly
# XY
style0 = vtk.vtkInteractorStyleRubberBand2D()
self.chartView.GetInteractor().SetInteractorStyle(style0)
self.chartView.GetScene().SetInteractorStyle(style0)
# Axis images
style1 = vtk.vtkInteractorStyleRubberBand2D()
self.axisView.GetInteractor().SetInteractorStyle(style1)
self.axisView.GetScene().SetInteractorStyle(style1)
# Set sizes for veritcal splitters
self.ui.splitter.setSizes([200,400])
# Connect signals and slots
QtCore.QObject.connect(self.ui.actionExit, QtCore.SIGNAL("triggered()"), self.fileExit)
# CORE setting up chart and axis images
test_id = 68
self.table = self.ds.GetNodeOneScaleCoeffTable(test_id)
line1 = vtkvtg.vtkMyPlotPoints()
# line1.DebugOn()
self.chart.AddPlot(line1) # POINTS
line1.SetInput(self.table, 0, 1)
line1.SetMarkerStyle(2)
line1.SetColor(0, 0, 0, 255)
# Tooltip image stack will now be owned by the tooltip, so need to do that differently...
id_list = self.ds.PIN[test_id]
image_stack = self.ds.GetProjectedImages(id_list)
self.chart.SetTooltipImageStack(image_stack)
self.chart.SetTooltipShowImage(True)
# self.chart.SetTooltipImageScalingFactor(2.0)
self.chart.SetTooltipImageTargetSize(40)
axis_images = self.ds.GetNodeBasisImages(test_id)
center_image = self.ds.GetNodeCenterImage(test_id)
self.ai.SetAxisImagesHorizontal()
self.ai.SetChartXY(self.chart)
self.ai.SetChartXYView(self.chartView)
self.ai.SetAxisImageStack(axis_images)
self.ai.SetCenterImage(center_image)
# Set up annotation link which will carry indices to parallel coordinates chart
# for highlighting outside selections (e.g. back from image_flow)
# This needs to carry indices, while image_flow link outputs pedigree ids
# so conversion happens in HighlightSelectionCallback
# data_col_idxs = vtk.vtkAnnotationLink()
# data_col_idxs.GetCurrentSelection().GetNode(0).SetFieldType(1) # Point
# data_col_idxs.GetCurrentSelection().GetNode(0).SetContentType(4) # 2 = PedigreeIds, 4 = Indices
# self.chart.SetDataColumnsLink(data_col_idxs)
# self.ai.SetDataColumnsLink(data_col_idxs)
# Create a annotation link to access selection in XY chart
annotationLink = vtk.vtkAnnotationLink()
#.........这里部分代码省略.........
开发者ID:emonson,项目名称:MultiScaleSVD,代码行数:101,代码来源:mypoints_ai1_split.py
示例17: om_display_vtp
#.........这里部分代码省略.........
# if a label is added, store the ID for the connectivity filter
cell_ids.append(i)
nb_meshes += 1
# Number of meshes
assert(nb_meshes<=4)
# Multiple viewports: 4
xmins = [0,.5,0,.5]; xmaxs = [0.5,1,0.5,1]; ymins = [0,0,.5,.5]; ymaxs = [0.5,0.5,1,1]
mappers = [vtk.vtkPolyDataMapper() for i in range(4)]
colorBars = [vtk.vtkScalarBarActor() for i in range(4)]
actors = [vtk.vtkActor() for i in range(4)]
rens = [vtk.vtkRenderer() for i in range(4)]
for i in range(4):
rens[i].SetViewport(xmins[i],ymins[i],xmaxs[i],ymaxs[i]);
# Display the meshes
if (i < nb_meshes):
# Create a connectivity filter based on cell seeded region (to display
# only one mesh per viewport)
conn = vtk.vtkPolyDataConnectivityFilter()
conn.SetInput(poly)
conn.SetExtractionModeToCellSeededRegions()
conn.AddSeed(cell_ids[i]); conn.Update()
actor_meshname = vtk.vtkTextActor();
actor_meshname.SetInput(cell_labels.GetValue(cell_ids[i]));
actor_meshname.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport();
actor_meshname.SetPosition(0.5, 0.85); tprop = actor_meshname.GetTextProperty(); tprop.SetFontSize(30)
tprop.SetFontFamilyToArial(); tprop.SetColor(1, 1, 1); tprop.SetJustificationToCentered()
mappers[i].SetInputConnection(conn.GetOutputPort())
mappers[i].SetScalarModeToUsePointData(); mappers[i].Update()
if nb_sources:
rens[i].AddActor2D(colorBars[i])
actors[i].SetMapper(mappers[i])
rens[i].AddActor2D(actor_meshname)
rens[i].AddActor(actors[i])
if (i == 0):
cam = rens[i].GetActiveCamera()
rens[i].ResetCamera()
else:
# Create a plane to cut
plane = vtk.vtkPlane(); plane.SetOrigin(0,0,0); plane.SetNormal(1,0,0);
# Create cutter
extract = vtk.vtkExtractPolyDataGeometry(); extract.SetInput(poly)
extract.SetImplicitFunction(plane); extract.ExtractBoundaryCellsOff()
mappers[i].SetInputConnection(extract.GetOutputPort())
mappers[i].SetScalarModeToUsePointData(); mappers[i].Update()
# Create plane actor
actors[i].SetMapper(mappers[i])
rens[i].AddActor(actors[i])
rens[i].SetActiveCamera(cam)
if nb_sources:
UpdateColorBar(colorBars[i], mappers[i])
renWin.AddRenderer(rens[i])
renWin.Render();
if nb_sources > 1:
# Slider
sliderWidget = vtk.vtkSliderWidget()
slider = vtk.vtkSliderRepresentation2D(); slider.SetMaximumValue(nb_sources-1)
slider.SetValue(n); slider.SetEndCapLength(0.01); slider.SetLabelFormat('%1.0f')
slider.SetSliderWidth(0.05); slider.SetSliderLength(1./nb_sources)
slider.GetPoint1Coordinate().SetCoordinateSystemToNormalizedViewport()
slider.GetPoint1Coordinate().SetValue(.0 ,0.02)
slider.GetPoint2Coordinate().SetCoordinateSystemToNormalizedViewport()
slider.GetPoint2Coordinate().SetValue(1. ,0.02);
sliderWidget.SetInteractor(iren); sliderWidget.SetRepresentation(slider);
sliderWidget.SetAnimationModeToAnimate(); sliderWidget.EnabledOn();
sliderWidget.AddObserver("InteractionEvent", SelectSource);
if not nb_sources == 0:
# The button for choosing Potentials/Currents
buttonWidget = vtk.vtkButtonWidget()
button = vtk.vtkTexturedButtonRepresentation2D(); button.SetNumberOfStates(2)
tex1r = vtk.vtkImageData(); tex2r = vtk.vtkImageData();
prop = vtk.vtkTextProperty(); prop.SetFontSize(24);
prop.SetColor(1,0,0); prop.SetBold(2); prop.SetShadow(2);
str2im = vtk.vtkFreeTypeStringToImage()
str2im.RenderString(prop,'Potentials',tex1r)
str2im.RenderString(prop,'Currents',tex2r)
button.SetButtonTexture(0, tex1r)
button.SetButtonTexture(1, tex2r)
buttonWidget.SetInteractor(iren);
buttonWidget.SetRepresentation(button);
button.SetPlaceFactor(1);
button.PlaceWidget([0., 100, 50, 500, 0, 0]);
buttonWidget.On()
buttonWidget.AddObserver(vtk.vtkCommand.StateChangedEvent,SelectMode);
# Selection
selactor = vtk.vtkActor()
view = vtk.vtkContextView(); view.GetRenderWindow().SetWindowName('Plot')
view.GetRenderWindow().SetPosition(600, 0); view.GetRenderWindow().SetSize(600, 600)
# Welcome text
text_init = vtk.vtkTextActor()
text_init.SetPosition(10, 300)
text_init.SetInput(welcome)
text_init.GetTextProperty().SetColor(1.0, 0.0, 0.0)
view.GetRenderer().AddActor2D(text_init)
view.GetInteractor().Initialize()
iren.AddObserver(vtk.vtkCommand.EndPickEvent,CleanPickData)
iren.Initialize()
iren.Start()
开发者ID:agramfort,项目名称:openmeeg_viz,代码行数:101,代码来源:om_display.py
示例18: om_display_vtk
def om_display_vtk(f,d = 0,n = 0):
"""
This function displays a VTK::vtk file generated with OpenMEEG.
Such a file defines a polydata, containing points and triangles of a single
mesh. Most often a EEG helmet mesh and associated leadfield.
"""
welcome = """Welcome\n\n
Move the slider to see all sources (columns of the input matrix)\n
Press 'r': To select points/cells.\n"""
# This callback function does updates the mappers for where n is the slider value
def CleanPickData(object, event):
ren.RemoveActor(selactor)
PickData(object, event, selactor, 0, view, text_init)
def SelectSource(object, event): # object will be the slider2D
slidervalue = int(round(object.GetRepresentation().GetValue()))
mapper.GetInput().GetPointData().SetActiveScalars("Potentials-"+str(slidervalue))
renWin.SetWindowName(renWin.GetWindowName()[0:(renWin.GetWindowName().find('-')+1)]+str(slidervalue))
UpdateColorBar(colorBar, mapper)
# A window with an interactor
renWin = vtk.vtkRenderWindow()
renWin.SetSize(600, 600)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.SetInteractorStyle(vtk.vtkInteractorStyleRubberBandPick())
# A picker (to pick points/cells)
picker = vtk.vtkRenderedAreaPicker()
iren.SetPicker(picker)
# Read the input file
reader = vtk.vtkPolyDataReader()
reader.SetFileName(f); reader.Update()
poly = reader.GetOutput()
renWin.SetWindowName(f+' Potentials-'+str(n))
# determine the number of sources
nb_sources = 0
for i in range(poly.GetPointData().GetNumberOfArrays()):
if poly.GetPointData().GetGlobalIds('Potentials-'+str(i)):
nb_sources += 1
if nb_sources == 0: #the file doesn't provide potentials
if not d.__class__ == int:
assert(d.shape[0] == poly.GetNumberOfPoints())
nb_sources = d.shape[1]
pot = [vtk.vtkDoubleArray() for j in range(d.shape[1])]
for j in range(d.shape[1]):
pot[j].SetName('Potentials-'+str(j))
for i in range(d.shape[0]):
pot[j].InsertNextValue(d[i,j])
poly.GetPointData().AddArray(pot[j])
poly.Update()
if not poly.GetPointData().GetGlobalIds('Indices'):
ind = vtk.vtkUnsignedIntArray()
ind.SetName('Indices')
for i in range(poly.GetNumberOfPoints()):
ind.InsertNextValue(i)
poly.GetPointData().AddArray(ind)
poly.GetPointData().SetActiveScalars('Potentials-'+str(n))
mapper = vtk.vtkPolyDataMapper()
colorBar = vtk.vtkScalarBarActor()
actor = vtk.vtkActor()
ren = vtk.vtkRenderer()
mapper.SetInput(poly)
mapper.SetScalarModeToUsePointDa
|
请发表评论