示例#1
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkCastToConcrete(), 'Processing.',
         ('vtkDataSet',), ('vtkDataSet',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
#!/usr/bin/env python
import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# create reader and warp data with vectors
reader = vtk.vtkDataSetReader()
reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/blow.vtk")
reader.SetScalarsName("thickness9")
reader.SetVectorsName("displacement9")
castToUnstructuredGrid = vtk.vtkCastToConcrete()
castToUnstructuredGrid.SetInputConnection(reader.GetOutputPort())
castToUnstructuredGrid.Update()
warp = vtk.vtkWarpVector()
warp.SetInputData(castToUnstructuredGrid.GetUnstructuredGridOutput())
# extract mold from mesh using connectivity
connect = vtk.vtkConnectivityFilter()
connect.SetInputConnection(warp.GetOutputPort())
connect.SetExtractionModeToSpecifiedRegions()
connect.AddSpecifiedRegion(0)
connect.AddSpecifiedRegion(1)
moldMapper = vtk.vtkDataSetMapper()
moldMapper.SetInputConnection(reader.GetOutputPort())
moldMapper.ScalarVisibilityOff()
moldActor = vtk.vtkActor()
moldActor.SetMapper(moldMapper)
moldActor.GetProperty().SetColor(.2,.2,.2)
moldActor.GetProperty().SetRepresentationToWireframe()
# extract parison from mesh using connectivity
connect2 = vtk.vtkConnectivityFilter()
connect2.SetInputConnection(warp.GetOutputPort())
示例#3
0
pl3d2.Update()
output2 = pl3d2.GetOutput().GetBlock(0)
pl3d = vtk.vtkMultiBlockPLOT3DReader()
pl3d.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin")
pl3d.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin")
pl3d.SetScalarFunctionNumber(120)
pl3d.SetVectorFunctionNumber(202)
pl3d.Update()
output = pl3d.GetOutput().GetBlock(0)
iso = vtk.vtkContourFilter()
iso.SetInputData(output)
iso.SetValue(0, -100000)
probe2 = vtk.vtkProbeFilter()
probe2.SetInputConnection(iso.GetOutputPort())
probe2.SetSourceData(output2)
cast2 = vtk.vtkCastToConcrete()
cast2.SetInputConnection(probe2.GetOutputPort())
normals = vtk.vtkPolyDataNormals()
normals.SetInputConnection(cast2.GetOutputPort())
normals.SetFeatureAngle(45)
isoMapper = vtk.vtkPolyDataMapper()
isoMapper.SetInputConnection(normals.GetOutputPort())
isoMapper.ScalarVisibilityOn()
isoMapper.SetScalarRange(output2.GetPointData().GetScalars().GetRange())
isoActor = vtk.vtkActor()
isoActor.SetMapper(isoMapper)
isoActor.GetProperty().SetColor(bisque)
outline = vtk.vtkStructuredGridOutlineFilter()
outline.SetInputData(output)
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInputConnection(outline.GetOutputPort())
示例#4
0
Contour0.SetValue(0, set_average)
#
contour_mapper = vtk.vtkHierarchicalPolyDataMapper()
contour_mapper.SetInputConnection(Contour0.GetOutputPort())
contour_mapper.SetImmediateModeRendering(1)
contour_mapper.SetScalarRange(0, 1)
contour_mapper.SetScalarVisibility(1)
#
contour_actor = vtk.vtkActor()
contour_actor.SetMapper(contour_mapper)
contour_actor.GetProperty().SetInterpolationToGouraud()
contour_actor.GetProperty().SetRepresentationToWireframe()
#contour_actor.GetProperty().SetRepresentationToSurface()

## outline
toRectilinearGrid = vtk.vtkCastToConcrete()
toRectilinearGrid.SetInput(DATAi)
toRectilinearGrid.Update()
#
outline = vtk.vtkStructuredGridOutlineFilter()
#outline.SetInputConnection(reader.GetOutputPort())
#outline.SetInputData(reader.GetOutput().GetBlock(0))
#outline.SetInput(reader.GetOutput().GetBlock(0))
outline.SetInput(toRectilinearGrid.GetRectilinearGridOutput())
#
outline_mapper = vtk.vtkHierarchicalPolyDataMapper()
outline_mapper.SetInputConnection(outline.GetOutputPort())
#
outline_actor = vtk.vtkActor()
outline_actor.SetMapper(outline_mapper)
示例#5
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

VTK_VARY_RADIUS_BY_VECTOR = 2
# create pipeline
#
reader = vtk.vtkGenericEnSightReader()
# Make sure all algorithms use the composite data pipeline
cdp = vtk.vtkCompositeDataPipeline()
reader.SetDefaultExecutivePrototype(cdp)
reader.SetCaseFileName("" + str(VTK_DATA_ROOT) + "/Data/EnSight/RectGrid_ascii.case")
reader.Update()
toRectilinearGrid = vtk.vtkCastToConcrete()
#    toRectilinearGrid SetInputConnection [reader GetOutputPort]
toRectilinearGrid.SetInputData(reader.GetOutput().GetBlock(0))
toRectilinearGrid.Update()
plane = vtk.vtkRectilinearGridGeometryFilter()
plane.SetInputData(toRectilinearGrid.GetRectilinearGridOutput())
plane.SetExtent(0,100,0,100,15,15)
tri = vtk.vtkTriangleFilter()
tri.SetInputConnection(plane.GetOutputPort())
warper = vtk.vtkWarpVector()
warper.SetInputConnection(tri.GetOutputPort())
warper.SetScaleFactor(0.05)
planeMapper = vtk.vtkDataSetMapper()
planeMapper.SetInputConnection(warper.GetOutputPort())
planeMapper.SetScalarRange(0.197813,0.710419)
planeActor = vtk.vtkActor()
示例#6
0
def vis_imgInit(ren):
    rdr = [None]*2
    txt = [None]*2
    plane = [None]*2
    tmap = [None]*2
    cast = [None]*2
    vmap = [None]*2
    actor = [None]*2
    lookupGrayscale = [None]*2
    lookupColor = [None]*2
    
    rdr[0] = 'vis_img_reader_' + ren[0]
    txt[0] = 'vis_img_texture_' + ren[0]
    plane[0] = 'vis_img_plane_' + ren[0]
    tmap[0] = 'vis_img_tmap_' + ren[0]
    vmap[0] = 'vis_img_map_' + ren[0]
    actor[0] = 'vis_img_actor_' + ren[0]
    lookupGrayscale[0] = 'vis_img_g8bitGrayscaleLUT_' + ren[0]
    lookupColor[0] = 'vis_img_gBlueToRedLUT_'+ ren[0]
    
    rdr[1] = vtk.vtkImageReader()
    rdr[1].SetDataScalarTypeToShort()
    rdr[1].SetFileDimensionality(2)
    rdr[1].SetDataByteOrderToBigEndian()
    
    txt[1] = vtk.vtkTexture()
    plane[1] = vtk.vtkPlaneSource()
    plane[1].SetResolution(1,1)
    plane[1].SetOrigin(0.,0.,0.)
    
    tmap[1] = vtk.vtkTextureMapToPlane()
    tmap[1].SetInputConnection(plane[1].GetOutputPort())
    
    cast[1] = vtk.vtkCastToConcrete()
    cast[1].SetInputConnection(tmap[1].GetOutputPort())
    
    vmap[1] = vtk.vtkPolyDataMapper()
    vmap[1].SetInputConnection(cast[1].GetOutputPort())
    
    actor[1] = vtk.vtkActor()
    actor[1].SetMapper(vmap[1])
    actor[1].SetTexture(txt[1])
    
    lookupGrayscale[1] = vtk.vtkLookupTable()
    lookupGrayscale[1].SetHueRange(0.,0.)
    lookupGrayscale[1].SetSaturationRange(0.,0.)
    lookupGrayscale[1].SetValueRange(0.,1.)
    lookupGrayscale[1].SetNumberOfColors(16384)
    lookupGrayscale[1].Build()
    
    lookupColor[1] = vtk.vtkLookupTable()
    lookupColor[1].SetHueRange(0.6667,0.)
    lookupColor[1].SetSaturationRange(1.,1.)
    lookupColor[1].SetValueRange(1.,1.)
    lookupColor[1].SetAlphaRange(1.,1.)
    lookupColor[1].SetNumberOfColors(16384)
    lookupColor[1].Build()
    
    setattr(vis,rdr[0], rdr)
    setattr(vis,txt[0], txt)
    setattr(vis,plane[0], plane)
    setattr(vis,tmap[0], tmap)
    setattr(vis,vmap[0], vmap)
    setattr(vis,actor[0], actor)
    setattr(vis,lookupGrayscale[0], lookupGrayscale)
    setattr(vis,lookupColor[0], lookupColor)
    return
示例#7
0
shrink = vtk.vtkImageShrink3D()
shrink.SetInputConnection(smooth.GetOutputPort())
shrink.SetShrinkFactors(2, 2, 1)
shrink.AveragingOn()

geometry = vtk.vtkImageDataGeometryFilter()
geometry.SetInputConnection(shrink.GetOutputPort())

geometryTexture = vtk.vtkTextureMapToPlane()
geometryTexture.SetInputConnection(geometry.GetOutputPort())
geometryTexture.SetOrigin(0, 0, 0)
geometryTexture.SetPoint1(padX - 1, 0, 0)
geometryTexture.SetPoint2(0, padY - 1, 0)

geometryPD = vtk.vtkCastToConcrete()
geometryPD.SetInputConnection(geometryTexture.GetOutputPort())
geometryPD.Update()

clip = vtk.vtkClipPolyData()
clip.SetInputData(geometryPD.GetPolyDataOutput())
clip.SetValue(5.5)
clip.GenerateClipScalarsOff()
clip.InsideOutOff()
clip.InsideOutOn()
clip.GetOutput().GetPointData().CopyScalarsOff()
clip.Update()

triangles = vtk.vtkTriangleFilter()
triangles.SetInputConnection(clip.GetOutputPort())
示例#8
0
isosurface.Update()

iso = vtk.vtkContourFilter()
#iso.SetInput(v2.GetOutput())
iso.SetInput(isosurface.GetOutput())
#iso.SetValue(0, .550)
#iso.SetNumberOfContours(13)
#iso.SetValue(0, 128)



probe = vtk.vtkProbeFilter()
probe.SetInput(iso.GetOutput())
probe.SetSource(coloroniso.GetOutput())

cast = vtk.vtkCastToConcrete()
cast.SetInput(probe.GetOutput())

normals = vtk.vtkPolyDataNormals()
#normals.SetMaxRecursionDepth(100)
normals.SetInput(cast.GetPolyDataOutput())
normals.SetFeatureAngle(45)

clut = vtk.vtkLookupTable()
clut.SetHueRange(0, .67)
clut.Build()
clut.SetValueRange(coloroniso.GetOutput().GetScalarRange())

##    normals = vtk.vtkPolyDataNormals()
##    normals.SetInput(iso.GetOutput())
##    normals.SetFeatureAngle(45)
示例#9
0
# by the mold into the final form. The data file contains several steps
# in time for the analysis.

import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# Create a reader to read the unstructured grid data. We use a
# vtkDataSetReader which means the type of the output is unknown until
# the data file is read. So we follow the reader with a
# vtkCastToConcrete and cast the output to vtkUnstructuredGrid.
reader = vtk.vtkDataSetReader()
reader.SetFileName(VTK_DATA_ROOT + "/Data/blow.vtk")
reader.SetScalarsName("thickness9")
reader.SetVectorsName("displacement9")
castToUnstructuredGrid = vtk.vtkCastToConcrete()
castToUnstructuredGrid.SetInputConnection(reader.GetOutputPort())
warp = vtk.vtkWarpVector()
warp.SetInputConnection(castToUnstructuredGrid.GetOutputPort())

# The connectivity filter extracts the first two regions. These are
# know to represent the mold.
connect = vtk.vtkConnectivityFilter()

connect.SetInputConnection(warp.GetOutputPort())
connect.SetExtractionModeToSpecifiedRegions()
connect.AddSpecifiedRegion(0)
connect.AddSpecifiedRegion(1)
moldMapper = vtk.vtkDataSetMapper()
moldMapper.SetInputConnection(reader.GetOutputPort())
moldMapper.ScalarVisibilityOff()
示例#10
0
	def InitVTKMethods(self):
		"""Initializes the VTK methods to be used."""
		self._probefilter=vtkProbeFilter()
		self._cast=vtkCastToConcrete()
		_IsoSurfaceSource_.InitVTKMethods(self)
示例#11
0
文件: clipArt.py 项目: 151706061/VTK
smooth = vtk.vtkImageGaussianSmooth()
smooth.SetDimensionality(2)
smooth.SetStandardDeviation(1,1)
smooth.SetInputConnection(connect.GetOutputPort())
shrink = vtk.vtkImageShrink3D()
shrink.SetInputConnection(smooth.GetOutputPort())
shrink.SetShrinkFactors(2,2,1)
shrink.AveragingOn()
geometry = vtk.vtkImageDataGeometryFilter()
geometry.SetInputConnection(shrink.GetOutputPort())
geometryTexture = vtk.vtkTextureMapToPlane()
geometryTexture.SetInputConnection(geometry.GetOutputPort())
geometryTexture.SetOrigin(0,0,0)
geometryTexture.SetPoint1(expr.expr(globals(), locals(),["padX","-","1"]),0,0)
geometryTexture.SetPoint2(0,expr.expr(globals(), locals(),["padY","-","1"]),0)
geometryPD = vtk.vtkCastToConcrete()
geometryPD.SetInputConnection(geometryTexture.GetOutputPort())
geometryPD.Update()
clip = vtk.vtkClipPolyData()
clip.SetInputData(geometryPD.GetPolyDataOutput())
clip.SetValue(5.5)
clip.GenerateClipScalarsOff()
clip.InsideOutOff()
clip.InsideOutOn()
clip.GetOutput().GetPointData().CopyScalarsOff()
clip.Update()
triangles = vtk.vtkTriangleFilter()
triangles.SetInputConnection(clip.GetOutputPort())
decimate = vtk.vtkDecimatePro()
decimate.SetInputConnection(triangles.GetOutputPort())
decimate.BoundaryVertexDeletionOn()
示例#12
0
文件: dem.py 项目: 151706061/VTK
    locals()[get_variable_name("geom", lod, "")] = vtk.vtkImageDataGeometryFilter()
    locals()[get_variable_name("geom", lod, "")].SetInputConnection(locals()[get_variable_name("shrink", lod, "")].GetOutputPort())
    locals()[get_variable_name("geom", lod, "")].ReleaseDataFlagOn()
    locals()[get_variable_name("warp", lod, "")] = vtk.vtkWarpScalar()
    locals()[get_variable_name("warp", lod, "")].SetInputConnection(locals()[get_variable_name("geom", lod, "")].GetOutputPort())
    locals()[get_variable_name("warp", lod, "")].SetNormal(0,0,1)
    locals()[get_variable_name("warp", lod, "")].UseNormalOn()
    locals()[get_variable_name("warp", lod, "")].SetScaleFactor(Scale)
    locals()[get_variable_name("warp", lod, "")].ReleaseDataFlagOn()
    locals()[get_variable_name("elevation", lod, "")] = vtk.vtkElevationFilter()
    locals()[get_variable_name("elevation", lod, "")].SetInputConnection(locals()[get_variable_name("warp", lod, "")].GetOutputPort())
    locals()[get_variable_name("elevation", lod, "")].SetLowPoint(0,0,lo)
    locals()[get_variable_name("elevation", lod, "")].SetHighPoint(0,0,hi)
    locals()[get_variable_name("elevation", lod, "")].SetScalarRange(lo,hi)
    locals()[get_variable_name("elevation", lod, "")].ReleaseDataFlagOn()
    locals()[get_variable_name("toPoly", lod, "")] = vtk.vtkCastToConcrete()
    locals()[get_variable_name("toPoly", lod, "")].SetInputConnection(locals()[get_variable_name("elevation", lod, "")].GetOutputPort())
    locals()[get_variable_name("normals", lod, "")] = vtk.vtkPolyDataNormals()
    locals()[get_variable_name("normals", lod, "")].SetInputConnection(locals()[get_variable_name("toPoly", lod, "")].GetOutputPort())
    locals()[get_variable_name("normals", lod, "")].SetFeatureAngle(60)
    locals()[get_variable_name("normals", lod, "")].ConsistencyOff()
    locals()[get_variable_name("normals", lod, "")].SplittingOff()
    locals()[get_variable_name("normals", lod, "")].ReleaseDataFlagOn()
    locals()[get_variable_name("demMapper", lod, "")] = vtk.vtkPolyDataMapper()
    locals()[get_variable_name("demMapper", lod, "")].SetInputConnection(locals()[get_variable_name("normals", lod, "")].GetOutputPort())
    locals()[get_variable_name("demMapper", lod, "")].SetScalarRange(lo,hi)
    locals()[get_variable_name("demMapper", lod, "")].SetLookupTable(lut)
    locals()[get_variable_name("demMapper", lod, "")].ImmediateModeRenderingOn()
    locals()[get_variable_name("demMapper", lod, "")].Update()
    demActor.AddLODMapper(locals()[get_variable_name("demMapper", lod, "")])
示例#13
0
colors = vtk.vtkElevationFilter()
colors.SetInputConnection(plane.GetOutputPort())
colors.SetLowPoint(-0.25, -0.25, -0.25)
colors.SetHighPoint(0.25, 0.25, 0.25)
planeMapper = vtk.vtkPolyDataMapper()
planeMapper.SetInputConnection(colors.GetOutputPort())
planeActor = vtk.vtkActor()
planeActor.SetMapper(planeMapper)
planeActor.GetProperty().SetRepresentationToWireframe()
# create simple poly data so we can apply glyph
squad = vtk.vtkSuperquadricSource()
squadColors = vtk.vtkElevationFilter()
squadColors.SetInputConnection(squad.GetOutputPort())
squadColors.SetLowPoint(-0.25, -0.25, -0.25)
squadColors.SetHighPoint(0.25, 0.25, 0.25)
squadCaster = vtk.vtkCastToConcrete()
squadCaster.SetInputConnection(squadColors.GetOutputPort())
squadTransform = vtk.vtkTransform()
transformSquad = vtk.vtkTransformPolyDataFilter()
transformSquad.SetInputConnection(squadColors.GetOutputPort())
transformSquad.SetTransform(squadTransform)
transformSquad.Update()


# procedure for generating glyphs
def Glyph(__vtk__temp0=0, __vtk__temp1=0):
    global res
    ptId = glypher.GetPointId()
    pd = glypher.GetPointData()
    xyz = glypher.GetPoint()
    x = lindex(xyz, 0)
示例#14
0
文件: vtkview.py 项目: badbytes/pymeg
def vtkrender(d1=None, d2=None):
    
    x = (arange(50.0)-25)/2.0
    y = (arange(50.0)-25)/2.0
    r = sqrt(x[:]**2+y**2)
    z = 5.0*signal.special.j0(r)  # Bessel function of order 0
    z1 = reshape(transpose(z), (-1,))
    point_data = vtk.vtkPointData(vtk.vtkScalars(z1))
    grid = vtk.vtkStructuredPoints((50,50, 1), (-12.5, -12.5, 0), (0.5, 0.5, 1))
    data = vtk.VtkData(grid, point_data)
    data.tofile('/tmp/test.vtk')
    d1 = d2 = '/tmp/test.vtk'
    
    #v2,v1,data1,data2 = inputs()
    if d1 == None:
        d1 = "/home/danc/E0058brain.vtk"
        #d1 = "/home/danc/vtk/data1.vtk"
    if d2 == None:
        d2 = "/home/danc/E0058MEG.vtk"
        #d2='/home/danc/vtk/data2.vtk'
        #d2 = "/home/danc/mrvtk_0003overlay.vtk"


    v1 = vtk.vtkStructuredPointsReader()

    #v1.SetFileName("/home/danc/mrvtk.vtk")
    v1.SetFileName(d1)
    v2 = vtk.vtkStructuredPointsReader()
    #v2.SetFileName("/home/danc/mrvtk_overlay.vtk")
    v2.SetFileName(d2)
    v1.SetLookupTableName('/home/danc/colortable.lut')
    v1.SetReadAllColorScalars
    v1.Update()
    v2.Update()


    global xMax, xMin, yMin, yMax, zMin, zMax, current_widget, slice_number
    xMin, xMax, yMin, yMax, zMin, zMax = v1.GetOutput().GetWholeExtent()

    spacing = v1.GetOutput().GetSpacing()
    sx, sy, sz = spacing

    origin = v1.GetOutput().GetOrigin()
    ox, oy, oz = origin

    # An outline is shown for context.
    outline = vtk.vtkOutlineFilter()
    outline.SetInput(v1.GetOutput())

    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInput(outline.GetOutput())

    outlineActor = vtk.vtkActor()
    outlineActor.SetMapper(outlineMapper)
    outlineActor.GetProperty().SetColor(1,1,1)

    # The shared picker enables us to use 3 planes at one time
    # and gets the picking order right
    picker = vtk.vtkCellPicker()
    picker.SetTolerance(0.005)

    # The 3 image plane widgets are used to probe the dataset.
    planeWidgetX = vtk.vtkImagePlaneWidget()
    planeWidgetX.DisplayTextOn()
    planeWidgetX.SetInput(v1.GetOutput())
    planeWidgetX.SetPlaneOrientationToXAxes()
    planeWidgetX.SetSliceIndex(int(round(xMax/2)))
    planeWidgetX.SetPicker(picker)
    planeWidgetX.SetKeyPressActivationValue("x")
    planeWidgetX.GetPlaneProperty().SetDiffuseColor((0,1,1))
    #planeWidgetX.GetPlaneProperty().SetColor(0,1,1)
    #planeWidgetX.GetPlaneProperty().SetSpecularColor(0,1,1)
    #planeWidgetX.GetPlaneProperty().SetAmbientColor(0,1,1)
    planeWidgetX.GetPlaneProperty().SetFrontfaceCulling(10)
    planeWidgetX.GetPlaneProperty().SetRepresentationToWireframe
    #planeWidgetX.GetColorMap()
    #print planeWidgetX.GetColorMap()
    #planeWidgetX.SetHueRange(0.667,0.0)
    #planeWidgetX.SetLookupTable('/home/danc/colortable.lut')

    prop1 = planeWidgetX.GetPlaneProperty()
    prop1.SetDiffuseColor(1, 0, 0)
    prop1.SetColor(1,0,0)
    prop1.SetSpecularColor(0, 1, 1)
    #print planeWidgetX.GetLookupTable()
    g = planeWidgetX.GetLookupTable()
    #print g



##    arrow = vtk.vtkArrowSource()
####    arrow.SetShaftRadius(100)
####    arrow.SetShaftResolution(80)
####    arrow.SetTipRadius(100)
####    arrow.SetTipLength(1000)
####    #arrow.SetTipResolution(80)
##    arrowMapper = vtk.vtkPolyDataMapper()
##    arrowMapper.SetInput(arrow.GetOutput())
##    arrowActor = vtk.vtkActor()
##    arrowActor.SetMapper(arrowMapper)
##    arrowActor.SetPosition(0, 0, 0)
##    arrowActor.GetProperty().SetColor(0, 1, 0)


    planeWidgetY = vtk.vtkImagePlaneWidget()
    planeWidgetY.DisplayTextOn()
    planeWidgetY.SetInput(v1.GetOutput())
    planeWidgetY.SetPlaneOrientationToYAxes()
    planeWidgetY.SetSliceIndex(int(round(yMax/2)))
    planeWidgetY.SetPicker(picker)
    planeWidgetY.SetKeyPressActivationValue("y")
    prop2 = planeWidgetY.GetPlaneProperty()
    prop2.SetColor(1, 1, 0)
    planeWidgetY.SetLookupTable(planeWidgetX.GetLookupTable())
    planeWidgetY.GetPlaneProperty().SetDiffuseColor(0,1,1)


    # for the z-slice, turn off texture interpolation:
    # interpolation is now nearest neighbour, to demonstrate
    # cross-hair cursor snapping to pixel centers
    planeWidgetZ = vtk.vtkImagePlaneWidget()

    planeWidgetZ.SetSliceIndex(100)
    planeWidgetZ.SetSlicePosition(100)
    planeWidgetZ.DisplayTextOn()
    planeWidgetZ.SetInput(v1.GetOutput())
    planeWidgetZ.SetPlaneOrientationToZAxes()
    planeWidgetZ.SetSliceIndex(int(round(yMax/2)))
    planeWidgetZ.SetPicker(picker)
    planeWidgetZ.SetKeyPressActivationValue("z")
    prop3 = planeWidgetZ.GetPlaneProperty()
    prop3.SetColor(0, 0, 1)
    planeWidgetZ.SetLookupTable(planeWidgetX.GetLookupTable())
    planeWidgetZ.GetPlaneProperty().SetDiffuseColor(0,1,1)

    filelist = [v2,v1];
    for i in filelist:


        coloroniso = vtk.vtkStructuredPointsReader()
        coloroniso.SetFileName(i.GetFileName())
        coloroniso.SetScalarsName("colors")
        coloroniso.Update()

        isosurface = vtk.vtkStructuredPointsReader()
        isosurface.SetFileName(i.GetFileName())
        isosurface.SetScalarsName("scalars")
        isosurface.Update()

        iso = vtk.vtkContourFilter()
        iso.SetInput(i.GetOutput())
        #iso.SetInput(isosurface.GetOutput())
        if i == v1:
            iso.SetValue(0, 20)
        else:
            iso.SetValue(0,10)
        #iso.SetNumberOfContours(10)

        probe = vtk.vtkProbeFilter()
        probe.SetInput(iso.GetOutput())
        probe.SetSource(coloroniso.GetOutput())

        cast = vtk.vtkCastToConcrete()
        cast.SetInput(probe.GetOutput())

        normals = vtk.vtkPolyDataNormals()
        #normals.SetMaxRecursionDepth(100)
        normals.SetInput(cast.GetPolyDataOutput())
        normals.SetFeatureAngle(45)

    ##    clut = vtk.vtkLookupTable()
    ##    clut.SetHueRange(0, .67)
    ##    clut.Build()
    ##    clut.SetValueRange(coloroniso.GetOutput().GetScalarRange())


    ##    normals = vtk.vtkPolyDataNormals()
    ##    normals.SetInput(iso.GetOutput())
    ##    normals.SetFeatureAngle(45)
        isoMapper = vtk.vtkPolyDataMapper()
        isoMapper.SetInput(normals.GetOutput())
        isoMapper.ScalarVisibilityOn()
        #isoMapper.SetColorModeToMapScalars()
        isoMapper.ColorByArrayComponent(0, 100)#("VelocityMagnitude", 0)

        isoMapper.SetScalarRange([1, 200])
    ##    isoMapper.SetLookupTable(clut)

        isoActor = vtk.vtkActor()
        isoActor.SetMapper(isoMapper)

    ##    isoActor.GetProperty().SetDiffuseColor([.5,.5,.5])
    ##    isoActor.GetProperty().SetSpecularColor([1,1,1])
    ##    isoActor.GetProperty().SetDiffuse(.5)
    ##    isoActor.GetProperty().SetSpecular(.5)
    ##    isoActor.GetProperty().SetSpecularPower(15)
    ##    isoActor.GetProperty().SetOpacity(.6)

        isoActor.GetProperty().SetDiffuseColor(1, .2, .2)
        isoActor.GetProperty().SetSpecular(.7)
        isoActor.GetProperty().SetSpecularPower(20)
        isoActor.GetProperty().SetOpacity(0.5)


        if i == v1:
            print 'under'
            isoActorUnderlay = isoActor
        else:
            print 'over'
            isoActorOverlay = isoActor




    # Create the RenderWindow and Renderer
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)

    # Add the outline actor to the renderer, set the background color and size
    ren.AddActor(outlineActor)
    #ren.AddActor(sphereActor)


    renWin.SetSize(700, 700)
    ren.SetBackground(0, 0, 0)

    current_widget = planeWidgetZ
    mode_widget = planeWidgetZ

    # Create the GUI
    # We first create the supporting functions (callbacks) for the GUI
    #
    # Align the camera so that it faces the desired widget
    def AlignCamera():
        #global ox, oy, oz, sx, sy, sz, xMax, xMin, yMax, yMin, zMax, \
        #      zMin, slice_number
        #global current_widget
        cx = ox+(0.5*(xMax-xMin))*sx
        cy = oy+(0.5*(yMax-yMin))*sy
        cz = oy+(0.5*(zMax-zMin))*sz
        vx, vy, vz = 0, 0, 0
        nx, ny, nz = 0, 0, 0
        iaxis = current_widget.GetPlaneOrientation()
        if iaxis == 0:
            vz = -1
            nx = ox + xMax*sx
            cx = ox + slice_number*sx
        elif iaxis == 1:
            vz = -1
            ny = oy+yMax*sy
            cy = oy+slice_number*sy
        else:
            vy = 1
            nz = oz+zMax*sz
            cz = oz+slice_number*sz

        px = cx+nx*2
        py = cy+ny*2
        pz = cz+nz*3

        camera = ren.GetActiveCamera()
        camera.SetViewUp(vx, vy, vz)
        camera.SetFocalPoint(cx, cy, cz)
        camera.SetPosition(px, py, pz)
        camera.OrthogonalizeViewUp()
        ren.ResetCameraClippingRange()
        renWin.Render()

    # Capture the display and place in a tiff
    def CaptureImage():
        w2i = vtk.vtkWindowToImageFilter()
        writer = vtk.vtkTIFFWriter()
        w2i.SetInput(renWin)
        w2i.Update()
        writer.SetInput(w2i.GetOutput())
        writer.SetFileName("/home/danc/image.tif")
        renWin.Render()
        writer.Write()


    # Align the widget back into orthonormal position,
    # set the slider to reflect the widget's position,
    # call AlignCamera to set the camera facing the widget
    def AlignXaxis():
        global xMax, xMin, current_widget, slice_number
        po = planeWidgetX.GetPlaneOrientation()
        if po == 3:
            planeWidgetX.SetPlaneOrientationToXAxes()
            slice_number = (xMax-xMin)/2
            planeWidgetX.SetSliceIndex(slice_number)
        else:
            slice_number = planeWidgetX.GetSliceIndex()

        current_widget = planeWidgetX

        slice.config(from_=xMin, to=xMax)
        slice.set(slice_number)
        AlignCamera()


    def AlignYaxis():
        global yMin, yMax, current_widget, slice_number
        po = planeWidgetY.GetPlaneOrientation()
        if po == 3:
            planeWidgetY.SetPlaneOrientationToYAxes()
            slice_number = (yMax-yMin)/2
            planeWidgetY.SetSliceIndex(slice_number)
        else:
            slice_number = planeWidgetY.GetSliceIndex()

        current_widget = planeWidgetY

        slice.config(from_=yMin, to=yMax)
        slice.set(slice_number)
        AlignCamera()

    def AlignZaxis():
        global yMin, yMax, current_widget, slice_number
        po = planeWidgetZ.GetPlaneOrientation()
        if po == 3:
            planeWidgetZ.SetPlaneOrientationToZAxes()
            slice_number = (zMax-zMin)/2
            planeWidgetZ.SetSliceIndex(slice_number)
        else:
            slice_number = planeWidgetZ.GetSliceIndex()

        current_widget = planeWidgetZ

        slice.config(from_=zMin, to=zMax)
        slice.set(slice_number)
        AlignCamera()

    ##################def flag(sw):


    def underlay():
        print 'under'
        global overunderstatus
        overunderstatus = 'under'
        isoActor = isoActorUnderlay
        u_button.config(relief='sunken')
        o_button.config(relief='raised')
        six=planeWidgetX.GetSliceIndex()
        siy=planeWidgetY.GetSliceIndex()
        siz=planeWidgetZ.GetSliceIndex()
        data = v1
        planeWidgetX.SetInput(data.GetOutput())
        planeWidgetY.SetInput(data.GetOutput())
        planeWidgetZ.SetInput(data.GetOutput())
        planeWidgetX.SetSliceIndex(six)
        planeWidgetY.SetSliceIndex(siy)
        planeWidgetZ.SetSliceIndex(siz)
        renWin.Render()


    def overlay():
        print 'over'
        global overunderstatus
        overunderstatus = 'over'
        isoActor = isoActorOverlay
        o_button.config(relief='sunken')
        u_button.config(relief='raised')
        six=planeWidgetX.GetSliceIndex()
        siy=planeWidgetY.GetSliceIndex()
        siz=planeWidgetZ.GetSliceIndex()
        data = v2
        planeWidgetX.SetInput(data.GetOutput())
        planeWidgetY.SetInput(data.GetOutput())
        planeWidgetZ.SetInput(data.GetOutput())
        planeWidgetX.SetSliceIndex(six)
        planeWidgetY.SetSliceIndex(siy)
        planeWidgetZ.SetSliceIndex(siz)
        renWin.Render()


    def render3d():
        print '3d rend'
        global buttonpos
        try:
            if overunderstatus == 'under':
                isoActor = isoActorUnderlay
            else:
                isoActor = isoActorOverlay
        except NameError:
            isoActor = isoActorUnderlay
        try:
            buttonpos
            print buttonpos
        except NameError:
            buttonpos = 0
            print buttonpos
            r_button.config(relief='sunken')
            ren.AddActor(isoActor)

            renWin.Render()
        else:
            if buttonpos == 0:
                buttonpos = 1
                r_button.config(relief='raised')
                ren.RemoveActor(isoActor)
                ren.RemoveActor(isoActorUnderlay)
                ren.RemoveActor(isoActorOverlay)
                renWin.Render()
            else:
                buttonpos = 0
                r_button.config(relief='sunken')
                print o_button
                ren.AddActor(isoActor)
                renWin.Render()
        return buttonpos

    # Set the widget's reslice interpolation mode
    # to the corresponding popup menu choice
    def SetInterpolation():
        global mode_widget, mode
        if mode.get() == 0:
            mode_widget.TextureInterpolateOff()
        else:
            mode_widget.TextureInterpolateOn()

        mode_widget.SetResliceInterpolate(mode.get())
        renWin.Render()

    # Share the popup menu among buttons, keeping track of associated
    # widget's interpolation mode
    def buttonEvent(event, arg=None):
        global mode, mode_widget, popm
        if arg == 0:
            mode_widget = planeWidgetX
        elif arg == 1:
            mode_widget = planeWidgetY
        elif arg == 2:
            mode_widget = planeWidgetZ
        else:
            return
        mode.set(mode_widget.GetResliceInterpolate())
        popm.entryconfigure(arg, variable=mode)
        popm.post(event.x + event.x_root, event.y + event.y_root)

    def SetSlice(sl):
        global current_widget
        current_widget.SetSliceIndex(int(sl))
        ren.ResetCameraClippingRange()
        renWin.Render()


    ###
    # Now actually create the GUI
    root = Tkinter.Tk()
    root.withdraw()
    top = Tkinter.Toplevel(root)

    # Define a quit method that exits cleanly.
    def quit(obj=root):
        print obj
        obj.quit()
        obj.destroy()
        #vtkrender.destroy()


    # Popup menu
    popm = Tkinter.Menu(top, tearoff=0)
    mode = Tkinter.IntVar()
    mode.set(1)
    popm.add_radiobutton(label="nearest", variable=mode, value=0,
                         command=SetInterpolation)
    popm.add_radiobutton(label="linear", variable=mode, value=1,
                         command=SetInterpolation)
    popm.add_radiobutton(label="cubic", variable=mode, value=2,
                         command=SetInterpolation)

    display_frame = Tkinter.Frame(top)
    display_frame.pack(side="top", anchor="n", fill="both", expand="false")

    # Buttons
    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",
                                    command=CaptureImage)
    quit_button.config(background='#C0C0C0')

    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)
    u_button = Tkinter.Button(ctrl_buttons, text="underlay", command=underlay)
    o_button = Tkinter.Button(ctrl_buttons, text="overlay", command=overlay)
    r_button = Tkinter.Button(ctrl_buttons, text="3d render", command=render3d)
    o_button.config(background='#FFFFFF')
    u_button.config(relief='sunken')



    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))
    u_button.bind("<Button-3>", lambda e: buttonEvent(e, 3))
    o_button.bind("<Button-3>", lambda e: buttonEvent(e, 4))
    r_button.bind("<Button-3>", lambda e: buttonEvent(e, 5))

    for i in (quit_button, capture_button, x_button, y_button, z_button, u_button, o_button, r_button):
        i.pack(side="left", expand="true", fill="both")


    # Create the render widget
    renderer_frame = Tkinter.Frame(display_frame)
    renderer_frame.pack(padx=3, pady=3,side="left", anchor="n",
                        fill="both", expand="false")

    render_widget = vtkTkRenderWindowInteractor(renderer_frame,
                                                rw=renWin, width=600,
                                                height=600)
    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.set(current_widget.GetSliceIndex())
    slice = Tkinter.Scale(top, from_=zMin, to=zMax, orient="horizontal",
                          command=SetSlice,variable=slice_number,
                          label="Slice")
    slice.pack(fill="x", expand="false")

    # Done with the GUI.
    ###

    # Set the interactor for the widgets
    iact = render_widget.GetRenderWindow().GetInteractor()
    planeWidgetX.SetInteractor(iact)
    planeWidgetX.On()
    planeWidgetY.SetInteractor(iact)
    planeWidgetY.On()
    planeWidgetZ.SetInteractor(iact)
    planeWidgetZ.On()

    # Create an initial interesting view
    cam1 = ren.GetActiveCamera()
    cam1.Elevation(210)
    cam1.SetViewUp(1, -1, 1)
    cam1.Azimuth(-145)
    ren.ResetCameraClippingRange()

    # Render it
    render_widget.Render()

    iact.Initialize()
    renWin.Render()
    iact.Start()

    # Start Tkinter event loop
    root.mainloop()
示例#15
0
colors = vtk.vtkElevationFilter()
colors.SetInputConnection(plane.GetOutputPort())
colors.SetLowPoint(-0.25,-0.25,-0.25)
colors.SetHighPoint(0.25,0.25,0.25)
planeMapper = vtk.vtkPolyDataMapper()
planeMapper.SetInputConnection(colors.GetOutputPort())
planeActor = vtk.vtkActor()
planeActor.SetMapper(planeMapper)
planeActor.GetProperty().SetRepresentationToWireframe()
# create simple poly data so we can apply glyph
squad = vtk.vtkSuperquadricSource()
squadColors = vtk.vtkElevationFilter()
squadColors.SetInputConnection(squad.GetOutputPort())
squadColors.SetLowPoint(-0.25,-0.25,-0.25)
squadColors.SetHighPoint(0.25,0.25,0.25)
squadCaster = vtk.vtkCastToConcrete()
squadCaster.SetInputConnection(squadColors.GetOutputPort())
squadTransform = vtk.vtkTransform()
transformSquad = vtk.vtkTransformPolyDataFilter()
transformSquad.SetInputConnection(squadColors.GetOutputPort())
transformSquad.SetTransform(squadTransform)
transformSquad.Update()
# procedure for generating glyphs
def Glyph (__vtk__temp0=0,__vtk__temp1=0):
    global res
    ptId = glypher.GetPointId()
    pd = glypher.GetPointData()
    xyz = glypher.GetPoint()
    x = lindex(xyz,0)
    y = lindex(xyz,1)
    length = glypher.GetInput(0).GetLength()
示例#16
0
文件: dem.py 项目: leo1978/berks-vtk
 locals()[get_variable_name("warp", lod, "")] = vtk.vtkWarpScalar()
 locals()[get_variable_name("warp", lod, "")].SetInputConnection(
     locals()[get_variable_name("geom", lod, "")].GetOutputPort())
 locals()[get_variable_name("warp", lod, "")].SetNormal(0, 0, 1)
 locals()[get_variable_name("warp", lod, "")].UseNormalOn()
 locals()[get_variable_name("warp", lod, "")].SetScaleFactor(Scale)
 locals()[get_variable_name("warp", lod, "")].ReleaseDataFlagOn()
 locals()[get_variable_name("elevation", lod,
                            "")] = vtk.vtkElevationFilter()
 locals()[get_variable_name("elevation", lod, "")].SetInputConnection(
     locals()[get_variable_name("warp", lod, "")].GetOutputPort())
 locals()[get_variable_name("elevation", lod, "")].SetLowPoint(0, 0, lo)
 locals()[get_variable_name("elevation", lod, "")].SetHighPoint(0, 0, hi)
 locals()[get_variable_name("elevation", lod, "")].SetScalarRange(lo, hi)
 locals()[get_variable_name("elevation", lod, "")].ReleaseDataFlagOn()
 locals()[get_variable_name("toPoly", lod, "")] = vtk.vtkCastToConcrete()
 locals()[get_variable_name("toPoly", lod, "")].SetInputConnection(
     locals()[get_variable_name("elevation", lod, "")].GetOutputPort())
 locals()[get_variable_name("normals", lod, "")] = vtk.vtkPolyDataNormals()
 locals()[get_variable_name("normals", lod, "")].SetInputConnection(
     locals()[get_variable_name("toPoly", lod, "")].GetOutputPort())
 locals()[get_variable_name("normals", lod, "")].SetFeatureAngle(60)
 locals()[get_variable_name("normals", lod, "")].ConsistencyOff()
 locals()[get_variable_name("normals", lod, "")].SplittingOff()
 locals()[get_variable_name("normals", lod, "")].ReleaseDataFlagOn()
 locals()[get_variable_name("demMapper", lod, "")] = vtk.vtkPolyDataMapper()
 locals()[get_variable_name("demMapper", lod, "")].SetInputConnection(
     locals()[get_variable_name("normals", lod, "")].GetOutputPort())
 locals()[get_variable_name("demMapper", lod, "")].SetScalarRange(lo, hi)
 locals()[get_variable_name("demMapper", lod, "")].SetLookupTable(lut)
 locals()[get_variable_name("demMapper", lod,