示例#1
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkStreamLine(), 'Processing.',
         ('vtkDataSet', 'vtkDataSet'), ('vtkPolyData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
    def create_stream_line(self,y1,y2,y3,n,r=10):

        seeds = vtk.vtkPointSource()
        seeds.SetNumberOfPoints(n)
        seeds.SetCenter(y1, y2, y3)
        seeds.SetRadius(r)
        seeds.SetDistributionToShell()



        integ = vtk.vtkRungeKutta4()
        streamline = vtk.vtkStreamLine()
        streamline.SetInputConnection(self.vec_reader.GetOutputPort())
        streamline.SetSourceConnection(seeds.GetOutputPort())
        streamline.SetMaximumPropagationTime(220)
        streamline.SetIntegrationStepLength(0.05)
        streamline.SetStepLength(0.5)
        streamline.SpeedScalarsOn()
        streamline.SetNumberOfThreads(1)
        streamline.SetIntegrationDirectionToIntegrateBothDirections()

        streamline.SetIntegrator(integ)
        streamline.SetSpeedScalars(220);

        streamlineMapper = vtk.vtkPolyDataMapper()
        streamlineMapper.SetInputConnection(streamline.GetOutputPort())
        streamlineMapper.SetLookupTable(self.arrowColor)


        streamline_actor = vtk.vtkActor()
        streamline_actor.SetMapper(streamlineMapper)
        streamline_actor.VisibilityOn()

        return streamline_actor
示例#3
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkStreamLine(),
                                       'Processing.',
                                       ('vtkDataSet', 'vtkDataSet'),
                                       ('vtkPolyData', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
    def create_stream_line(self,x,y,z,opa):

        rake = vtk.vtkLineSource()
        rake.SetPoint1(x, -y, z)
        rake.SetPoint2(x, y, z)
        rake.SetResolution(150)

        """
        rake_mapper = vtk.vtkPolyDataMapper()
        rake_mapper.SetInputConnection(rake.GetOutputPort())
        rake_actor = vtk.vtkActor()
        rake_actor.SetMapper(rake_mapper)
        self.ren.AddActor(rake_actor)
        """

        integ = vtk.vtkRungeKutta4()
        streamline = vtk.vtkStreamLine()
        streamline.SetInputConnection(self.vec_reader.GetOutputPort())
        streamline.SetSourceConnection(rake.GetOutputPort())
        streamline.SetIntegrator(integ)
        streamline.SetMaximumPropagationTime(300)
        streamline.SetIntegrationStepLength(0.01)
        streamline.SetIntegrationDirectionToForward()
        streamline.SpeedScalarsOn()
        streamline.SetStepLength(0.05)

        scalarSurface = vtk.vtkRuledSurfaceFilter()
        scalarSurface.SetInputConnection(streamline.GetOutputPort())
        #scalarSurface.SetOffset(0)
        scalarSurface.SetOnRatio(1)
        scalarSurface.PassLinesOn()
        scalarSurface.SetRuledModeToPointWalk()
        scalarSurface.SetDistanceFactor(30)

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(scalarSurface.GetOutputPort())
        #mapper.SetScalarRange(self.vec_reader.GetOutput().GetScalarRange())
        mapper.SetLookupTable(self.arrowColor)

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetOpacity(opa)

        return actor
    def initStreamlines(self):
        print "initializing Streamlines"
        RK4 = vtk.vtkRungeKutta4()
        self.initSeedPoint()

        self.vtkStreamline = vtk.vtkStreamLine()
        self.vtkStreamline.SetInputData(self.vtkStructuredGrid)
        self.vtkStreamline.SetSourceConnection(self.vtkSeeds.GetOutputPort())
        self.vtkStreamline.SetMaximumPropagationTime(500)
        self.vtkStreamline.SetIntegrationStepLength(.2)
        self.vtkStreamline.SetStepLength(0.001)
        self.vtkStreamline.SetNumberOfThreads(1)
        self.vtkStreamline.SetIntegrationDirectionToIntegrateBothDirections()
        self.vtkStreamline.SetIntegrator(RK4)
        self.vtkStreamline.VorticityOn()

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(self.vtkStreamline.GetOutputPort())
        self.vtkFlowActor.SetMapper(mapper)
        self.vtkFlowActor.VisibilityOn()
    def create_stream_line(self,y1,y2,y3,n,r=10,tr=2):

        seeds = vtk.vtkPointSource()
        seeds.SetNumberOfPoints(n)
        seeds.SetCenter(y1, y2, y3)
        seeds.SetRadius(r)
        seeds.SetDistributionToShell()


        integ = vtk.vtkRungeKutta4()
        streamline = vtk.vtkStreamLine()
        streamline.SetInputConnection(self.vec_reader.GetOutputPort())
        streamline.SetSourceConnection(seeds.GetOutputPort())
        streamline.SetMaximumPropagationTime(220)
        streamline.SetIntegrationStepLength(0.05)
        streamline.SetStepLength(0.5)
        streamline.SpeedScalarsOn()
        streamline.SetNumberOfThreads(1)
        streamline.SetIntegrationDirectionToIntegrateBothDirections()
        streamline.SetIntegrator(integ)
        streamline.SetSpeedScalars(220);


        streamline_mapper = vtk.vtkPolyDataMapper()
        streamline_mapper.SetInputConnection(streamline.GetOutputPort())


        streamTube = vtk.vtkTubeFilter()
        streamTube.SetInputConnection(streamline.GetOutputPort())
        streamTube.SetRadius(tr)
        streamTube.SetNumberOfSides(12)
        streamTube.SetVaryRadiusToVaryRadiusByVector()
        mapStreamTube = vtk.vtkPolyDataMapper()
        mapStreamTube.SetInputConnection(streamTube.GetOutputPort())
        mapStreamTube.SetLookupTable(self.arrowColor)

        streamTubeActor = vtk.vtkActor()
        streamTubeActor.SetMapper(mapStreamTube)
        streamTubeActor.GetProperty().BackfaceCullingOn()

        return streamTubeActor
示例#7
0
    def __init__ (self, mod_m):
        debug ("In PointStreamer::__init__ ()")
        Common.state.busy ()
        Base.Objects.Module.__init__ (self, mod_m)
        self.sphere_src = vtk.vtkSphereSource ()
        self.sphere_map = vtk.vtkPolyDataMapper ()
        self.sphere_act = vtk.vtkActor ()        
        self.seed = SeedManager ()
        self.radius = 1.0
        self.cen = [0.0, 0.0, 0.0]
        self.n_pnt = 50
        self.strmln_mode = 0
        self.color_mode = 1 # 1 is vector, 0 is scalar, -1 is no color
        self.integration_mode = 2 # 2 is Runge-Kutta 2 and 4 is RK 4.

        self.strmln = vtk.vtkStreamLine ()
        self.ribbonf = vtk.vtkRibbonFilter ()
        self.tubef = vtk.vtkTubeFilter ()
        self.mapper = self.stream_map = vtk.vtkPolyDataMapper ()
        self.actor = self.stream_act = vtk.vtkActor ()
        self.done_init = 0
        Common.state.idle ()
示例#8
0
ctf = vtk.vtkLookupTable()
ctf.SetHueRange(0.667, 0.0)
ctf.SetValueRange(1.0, 1.0)
ctf.SetSaturationRange(1.0, 1.0)
ctf.SetTableRange(a, b)

# A plane for the seeds
plane = vtk.vtkPlaneSource()
plane.SetOrigin(xmi, math.ceil(ymi), zmi)
plane.SetPoint1(xma, math.ceil(ymi), zmi)
plane.SetPoint2(xmi, math.ceil(ymi), zma)
plane.SetXResolution(6)
plane.SetYResolution(6)

# Streamlines
stream = vtk.vtkStreamLine()
stream.SetSource(plane.GetOutput())
stream.SetInput(reader.GetOutput())
stream.SetIntegrationDirectionToForward()
stream.SetIntegrator(vtk.vtkRungeKutta4())
stream.SetStepLength(0.1)

streamMapper = vtk.vtkPolyDataMapper()
streamMapper.SetLookupTable(ctf)
streamMapper.SetInput(stream.GetOutput())
streamMapper.SetScalarRange(a, b)
streamActor = vtk.vtkActor()
streamActor.SetMapper(streamMapper)
streamActor.GetProperty().SetLineWidth(3.0)

#Colour Bar
# Start by loading some data.
pl3d = vtk.vtkMultiBlockPLOT3DReader()
pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin")
pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin")
pl3d.SetScalarFunctionNumber(100)
pl3d.SetVectorFunctionNumber(202)
pl3d.Update()

seeds = vtk.vtkPlaneSource()
seeds.SetXResolution(4)
seeds.SetYResolution(4)
seeds.SetOrigin(2,-2,26)
seeds.SetPoint1(2, 2,26)
seeds.SetPoint2(2,-2,32)

streamline = vtk.vtkStreamLine()
streamline.SetInputData(pl3d.GetOutput().GetBlock(0))
streamline.SetSourceConnection(seeds.GetOutputPort())
streamline.SetMaximumPropagationTime(200)
streamline.SetIntegrationStepLength(.2)
streamline.SetStepLength(0.001)
streamline.SetNumberOfThreads(1)
streamline.SetIntegrationDirectionToForward()
streamline.VorticityOn()

streamline_mapper = vtk.vtkPolyDataMapper()
streamline_mapper.SetInputConnection(streamline.GetOutputPort())
streamline_actor = vtk.vtkActor()
streamline_actor.SetMapper(streamline_mapper)
streamline_actor.VisibilityOn()
示例#10
0
map_cl = vtk.vtkPolyDataMapper()
map_cl.SetInputConnection(glyph_cl.GetOutputPort())
map_cl.SetColorModeToMapScalars()
map_cl.SetLookupTable(lut_curl)
eval(map_cl.SetScalarRange(v0, v1))

actor_cl = vtk.vtkActor()
actor_cl.SetMapper(map_cl)


# streamers ###################################################################
#
integ = vtk.vtkRungeKutta4()
  
streams = vtk.vtkStreamLine()
streams.SetIntegrator(integ)
streams.SetInputConnection(v_reader.GetOutputPort())
streams.SetSourceConnection(InputPlaneTF.GetOutputPort())
streams.SetMaximumPropagationTime(5.0)
streams.SetIntegrationDirectionToForward()
streams.SetIntegrationStepLength(0.1)
streams.SetStepLength(0.01)
streams.SpeedScalarsOn()
streams.SetTerminalSpeed(0.01)

def SetLen(value):
	streams.SetMaximumPropagationTime(s1.get())
	reWin.Render()

def SetDir():
示例#11
0
ctf = vtk.vtkLookupTable()
ctf.SetHueRange(0.667, 0.0)
ctf.SetValueRange(1.0, 1.0)
ctf.SetSaturationRange(1.0, 1.0)
ctf.SetTableRange(a,b)

# A plane for the seeds
plane = vtk.vtkPlaneSource()
plane.SetOrigin(xmi,math.ceil(ymi),zmi)
plane.SetPoint1(xma,math.ceil(ymi),zmi)
plane.SetPoint2(xmi,math.ceil(ymi),zma)
plane.SetXResolution(6)
plane.SetYResolution(6)

# Streamlines
stream = vtk.vtkStreamLine()
stream.SetSource(plane.GetOutput())
stream.SetInput(reader.GetOutput())
stream.SetIntegrationDirectionToForward()
stream.SetIntegrator(vtk.vtkRungeKutta4())
stream.SetStepLength(0.1)

streamMapper = vtk.vtkPolyDataMapper()
streamMapper.SetLookupTable(ctf)
streamMapper.SetInput(stream.GetOutput())
streamMapper.SetScalarRange(a,b)
streamActor = vtk.vtkActor()
streamActor.SetMapper(streamMapper)
streamActor.GetProperty().SetLineWidth(3.0)

#Colour Bar
示例#12
0
outline.SetInputData(pl3d_output)

outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInputConnection(outline.GetOutputPort())

outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)

seeds = vtk.vtkLineSource()
seeds.SetPoint1(15, -5, 32)
seeds.SetPoint2(15, 5, 32)
seeds.SetResolution(10)

integ = vtk.vtkRungeKutta4()

sl = vtk.vtkStreamLine()
sl.SetIntegrator(integ)
sl.SetInputData(pl3d_output)
sl.SetSourceConnection(seeds.GetOutputPort())
sl.SetMaximumPropagationTime(0.1)
sl.SetIntegrationStepLength(0.1)
sl.SetIntegrationDirectionToBackward()
sl.SetStepLength(0.001)

tube = vtk.vtkTubeFilter()
tube.SetInputConnection(sl.GetOutputPort())
tube.SetRadius(0.1)

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(tube.GetOutputPort())
示例#13
0
isoVzActor.GetProperty().SetColor(0.4,0.5,1)
mf = vtk.vtkMergeFields()
mf.SetInputConnection(sf.GetOutputPort())
mf.SetOutputField("merged","POINT_DATA")
mf.SetNumberOfComponents(3)
mf.Merge(0,"vy",0)
mf.Merge(1,"vz",0)
mf.Merge(2,"vx",0)
#mf.Print()
aa = vtk.vtkAssignAttribute()
aa.SetInputConnection(mf.GetOutputPort())
aa.Assign("merged","SCALARS","POINT_DATA")
aa2 = vtk.vtkAssignAttribute()
aa2.SetInputConnection(aa.GetOutputPort())
aa2.Assign("SCALARS","VECTORS","POINT_DATA")
sl = vtk.vtkStreamLine()
sl.SetInputConnection(aa2.GetOutputPort())
sl.SetStartPosition(2,-2,26)
sl.SetMaximumPropagationTime(40)
sl.SetIntegrationStepLength(0.2)
sl.SetIntegrationDirectionToForward()
sl.SetStepLength(0.001)
rf = vtk.vtkRibbonFilter()
rf.SetInputConnection(sl.GetOutputPort())
rf.SetWidth(1.0)
rf.SetWidthFactor(5)
slMapper = vtk.vtkPolyDataMapper()
slMapper.SetInputConnection(rf.GetOutputPort())
slMapper.ImmediateModeRenderingOn()
slActor = vtk.vtkActor()
slActor.SetMapper(slMapper)
示例#14
0
# select the integration order to use (RungeKutta order 4) and
# associate it with the streamer. The start position is the position
# in world space where we want to begin streamline integration; and we
# integrate in both directions. The step length is the length of the
# line segments that make up the streamline (i.e., related to
# display). The IntegrationStepLength specifies the integration step
# length as a fraction of the cell size that the streamline is in.

# Create source for streamtubes
seeds = vtk.vtkPointSource()
seeds.SetRadius(0.15)
seeds.SetCenter(0.1, 2.1, 0.5)
seeds.SetNumberOfPoints(6)

integ = vtk.vtkRungeKutta4()
streamer = vtk.vtkStreamLine()
streamer.SetInputConnection(reader.GetOutputPort())
streamer.SetSource(seeds.GetOutput())
streamer.SetMaximumPropagationTime(500)
streamer.SetStepLength(0.5)
streamer.SetIntegrationStepLength(0.05)
streamer.SetIntegrationDirectionToIntegrateBothDirections()
streamer.SetIntegrator(integ)

# The tube is wrapped around the generated streamline. By varying the
# radius by the inverse of vector magnitude, we are creating a tube
# whose radius is proportional to mass flux (in incompressible flow).
streamTube = vtk.vtkTubeFilter()
streamTube.SetInputConnection(streamer.GetOutputPort())
streamTube.SetRadius(0.02)
streamTube.SetNumberOfSides(12)
示例#15
0
def main(vector_file, magnitude_file):

    ColorRange = vtk.vtkLookupTable()
    ColorRange.SetTableRange(0, 1)
    ColorRange.SetHueRange(0, 1)
    ColorRange.SetSaturationRange(1, 1)
    ColorRange.SetAlphaRange(0.3, 0.5)
    ColorRange.Build()

    reader = vtk.vtkStructuredPointsReader()
    reader.SetFileName(vector_file)
    reader.Update()

    data = reader.GetOutput()

    range1 = data.GetScalarRange()
    v0 = range1[0]
    v1 = range1[1]

    reader_magnitude = vtk.vtkStructuredPointsReader()
    reader_magnitude.SetFileName(magnitude_file)
    reader_magnitude.Update()

    contour = vtk.vtkContourFilter()
    contour.SetInput(reader_magnitude.GetOutput())
    contour.SetValue(0, 1)

    normals = vtk.vtkPolyDataNormals()
    normals.SetInput(contour.GetOutput())
    normals.SetFeatureAngle(60)
    normals.ConsistencyOff()
    normals.SplittingOff()

    mapper_magnitude = vtk.vtkPolyDataMapper()
    mapper_magnitude.SetInput(normals.GetOutput())
    mapper_magnitude.SetLookupTable(ColorRange)
    mapper_magnitude.SetColorModeToMapScalars()
    mapper_magnitude.SetScalarRange(v0, v1)

    actor_magnitude = vtk.vtkActor()
    actor_magnitude.SetMapper(mapper_magnitude)

    sphere = vtk.vtkSphereSource()
    sphere.SetRadius(2)
    sphere.SetCenter(15, 15, 15)  # Critical point for all 3 test datasets
    sphere.SetThetaResolution(10)

    integrator = vtk.vtkRungeKutta4()

    stream = vtk.vtkStreamLine()
    stream.SetInput(reader.GetOutput())
    stream.SetSource(sphere.GetOutput())
    stream.SetIntegrator(integrator)
    stream.SetMaximumPropagationTime(500)
    stream.SetIntegrationStepLength(0.1)
    stream.SetIntegrationDirectionToIntegrateBothDirections()
    stream.SetStepLength(0.1)

    scalarSurface = vtk.vtkRuledSurfaceFilter()
    scalarSurface.SetInput(stream.GetOutput())
    scalarSurface.SetOffset(0)
    scalarSurface.SetOnRatio(2)
    scalarSurface.PassLinesOn()
    scalarSurface.SetRuledModeToPointWalk()
    scalarSurface.SetDistanceFactor(50)

    tube = vtk.vtkTubeFilter()
    tube.SetInput(scalarSurface.GetOutput())
    tube.SetRadius(0.1)
    tube.SetNumberOfSides(6)

    dataMapper = vtk.vtkPolyDataMapper()
    dataMapper.SetInput(tube.GetOutput())
    dataMapper.SetScalarRange(v0, v1)
    dataMapper.SetLookupTable(ColorRange)

    dataActor = vtk.vtkActor()
    dataActor.SetMapper(dataMapper)

    probe = vtk.vtkProbeFilter()
    probe.SetInput(stream.GetOutput())
    probe.SetSource(reader.GetOutput())

    mask = vtk.vtkMaskPoints()
    mask.SetInput(probe.GetOutput())
    mask.SetOnRatio(60)
    mask.RandomModeOn()

    cone = vtk.vtkConeSource()
    cone.SetResolution(8)
    cone.SetHeight(1.0)
    cone.SetRadius(0.2)

    transform = vtk.vtkTransform()
    transform.Translate(0, 0, 0)

    transformFilter = vtk.vtkTransformPolyDataFilter()
    transformFilter.SetInput(cone.GetOutput())
    transformFilter.SetTransform(transform)

    glyph = vtk.vtkGlyph3D()
    glyph.SetInput(mask.GetOutput())
    glyph.SetSource(transformFilter.GetOutput())
    glyph.SetScaleModeToScaleByVector()
    glyph.SetScaleFactor(1.5)
    glyph.SetVectorModeToUseVector()
    glyph.SetColorModeToColorByVector()

    glyphMapper = vtk.vtkPolyDataMapper()
    glyphMapper.SetInput(glyph.GetOutput())
    glyphMapper.SetLookupTable(ColorRange)

    glyphActor = vtk.vtkActor()
    glyphActor.SetMapper(glyphMapper)

    outline = vtk.vtkOutlineFilter()
    outline.SetInput(reader.GetOutput())

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

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

    criticalMarker = vtk.vtkSphereSource()
    criticalMarker.SetRadius(1.0)
    criticalMarker.SetCenter(15, 15, 15)
    criticalMarker.SetThetaResolution(10)

    criticalMapper = vtk.vtkPolyDataMapper()
    criticalMapper.SetInput(criticalMarker.GetOutput())

    criticalActor = vtk.vtkActor()
    criticalActor.SetMapper(criticalMapper)
    criticalActor.GetProperty().SetColor(1, 1, 0)
    criticalActor.GetProperty().SetOpacity(0.5)

    colorActor = vtk.vtkScalarBarActor()
    colorActor.SetLookupTable(ColorRange)

    renderer = vtk.vtkRenderer()

    renderer_window = vtk.vtkRenderWindow()
    renderer_window.AddRenderer(renderer)
    renderer_window.SetSize(512, 512)

    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderer_window)
    renderer.AddActor(actor_magnitude)
    renderer.AddActor(outlineActor)
    renderer.AddActor(criticalActor)
    renderer.AddActor(colorActor)
    renderer.AddActor(dataActor)
    renderer.AddActor(glyphActor)

    renderer.ResetCamera()

    style = vtk.vtkInteractorStyleTrackballCamera()
    # style = vtk.vtkInteractorStyleRubberBandZoom()
    # style = vtk.vtkInteractorStyleTerrain()
    interactor.SetInteractorStyle(style)

    renderer_window.Render()
    interactor.Start()
示例#16
0
def Main():
    global ren
    # Create the RenderWindow, Renderer and both Actors
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.SetMultiSamples(0)
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    iren.RemoveObservers('RightButtonPressEvent')
    iren.AddObserver('RightButtonPressEvent', print_camera_settings, 1.0)
    iren.AddObserver('RightButtonPressEvent', after_print_camera_settings,
                     -1.0)

    print "data: %s %s" % (sys.argv[1], sys.argv[2])

    cfdreader = vtk.vtkStructuredPointsReader()
    cfdreader.SetFileName(sys.argv[1])

    # setup wing data
    wingReader = vtk.vtkUnstructuredGridReader()
    wingReader.SetFileName(sys.argv[2])
    wingReader.Update()
    wingMapper = vtk.vtkDataSetMapper()
    wingMapper.SetInputConnection(wingReader.GetOutputPort())
    wingActor = vtk.vtkActor()
    wingActor.SetMapper(wingMapper)
    wingActor.GetProperty().SetColor(.4, .4, .4)

    bRakesToActor = [True, True, True]
    bWingToActor = True

    datamin = 0
    datamax = 230

    lut = vtk.vtkColorTransferFunction()
    lut.SetColorSpaceToHSV()
    lut.AddHSVPoint(datamin, 0, 1, 1)
    dis = float(datamax - datamin) / 7
    for i in range(0, 8):
        lut.AddHSVPoint(float(datamin + dis * i), 0.1 * i, 1, 1)

    colorBar = vtk.vtkScalarBarActor()
    colorBar.SetLookupTable(lut)
    colorBar.SetTitle("")
    colorBar.SetNumberOfLabels(6)
    colorBar.SetLabelFormat("%4.0f")
    colorBar.SetPosition(0.9, 0.1)
    colorBar.SetWidth(0.05)
    colorBar.SetHeight(0.4)
    ren.AddActor(colorBar)

    rakes = [vtk.vtkLineSource(), vtk.vtkLineSource(), vtk.vtkLineSource()]
    rakes[0].SetPoint1(-230, -230, 0)
    rakes[0].SetPoint2(230, 230, 0)
    rakes[0].SetResolution(50)

    rakes[1].SetPoint1(230, -230, 0)
    rakes[1].SetPoint2(-230, 230, 0)
    rakes[1].SetResolution(50)

    #     rakes[2].SetPoint1(0, -200, 10)
    #     rakes[2].SetPoint2(0, 200, 10)
    #     rakes[2].SetResolution(50)

    for i in range(0, len(rakes)):
        rakeMapper = vtk.vtkPolyDataMapper()
        rakeMapper.SetInputConnection(rakes[i].GetOutputPort())
        rakeActor = vtk.vtkActor()
        rakeActor.SetMapper(rakeMapper)

        integ = vtk.vtkRungeKutta4()
        streamLine = vtk.vtkStreamLine()
        streamLine.SetInputConnection(cfdreader.GetOutputPort())
        streamLine.SetSourceConnection(rakes[i].GetOutputPort())
        streamLine.SetMaximumPropagationTime(50)
        streamLine.SetIntegrationStepLength(.1)
        streamLine.SetStepLength(0.001)
        streamLine.SetIntegrationDirectionToForward()
        streamLine.SetIntegrator(integ)
        streamLine.SpeedScalarsOn()

        scalarSurface = vtk.vtkRuledSurfaceFilter()
        scalarSurface.SetInputConnection(streamLine.GetOutputPort())
        scalarSurface.SetOffset(0)
        scalarSurface.SetOnRatio(0)
        #         scalarSurface.PassLinesOn()
        scalarSurface.SetRuledModeToPointWalk()
        #         scalarSurface.SetDistanceFactor(40)

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(scalarSurface.GetOutputPort())
        mapper.SetLookupTable(lut)
        mapper.SetScalarRange(cfdreader.GetOutput().GetScalarRange())
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetColor(0, 1, 0)
        actor.GetProperty().SetOpacity(0.5)

        if bRakesToActor[i]:
            ren.AddActor(actor)

    if bWingToActor:
        ren.AddActor(wingActor)

    ren.SetBackground(0, 0, 0)
    renWin.SetSize(1600, 900)

    ren.ResetCamera()
    ren.GetActiveCamera().SetClippingRange(417.55784439078775,
                                           1491.5763714138557)
    ren.GetActiveCamera().SetFocalPoint(118.72183980792761,
                                        0.00012969970703125,
                                        36.469017028808594)
    ren.GetActiveCamera().SetPosition(680.0192576650034, 16.65944318371372,
                                      790.5781258299678)
    ren.GetActiveCamera().SetViewUp(-0.802117714199773, -0.005112780752923929,
                                    0.5971440630533839)

    # Render
    iren.Initialize()
    renWin.Render()
    iren.Start()
示例#17
0
xyx_file = "combxyz.bin"
q_file = "combq.bin"
pl3d.SetXYZFileName(xyx_file)
pl3d.SetQFileName(q_file)
pl3d.SetScalarFunctionNumber(100)
pl3d.SetVectorFunctionNumber(202)
pl3d.Update()

seeds = vtk.vtkPlaneSource()
seeds.SetXResolution(4)
seeds.SetYResolution(4)
seeds.SetOrigin(2, -2, 26)
seeds.SetPoint1(2, 2, 26)
seeds.SetPoint2(2, -2, 32)

streamline = vtk.vtkStreamLine()
streamline.SetInputData(pl3d.GetOutput().GetBlock(0))
streamline.SetSourceConnection(seeds.GetOutputPort())
streamline.SetMaximumPropagationTime(200)
streamline.SetIntegrationStepLength(.2)
streamline.SetStepLength(0.001)
streamline.SetNumberOfThreads(1)
streamline.SetIntegrationDirectionToForward()
streamline.VorticityOn()

streamline_mapper = vtk.vtkPolyDataMapper()
streamline_mapper.SetInputConnection(streamline.GetOutputPort())
streamline_actor = vtk.vtkActor()
streamline_actor.SetMapper(streamline_mapper)
streamline_actor.VisibilityOn()
示例#18
0
cutActor = vtk.vtkActor()
cutActor.SetMapper(cutMapper)
iso = vtk.vtkContourFilter()
iso.SetInputData(toRectilinearGrid.GetRectilinearGridOutput())
iso.SetValue(0, 0.7)
normals = vtk.vtkPolyDataNormals()
normals.SetInputConnection(iso.GetOutputPort())
normals.SetFeatureAngle(45)
isoMapper = vtk.vtkPolyDataMapper()
isoMapper.SetInputConnection(normals.GetOutputPort())
isoMapper.ScalarVisibilityOff()
isoActor = vtk.vtkActor()
isoActor.SetMapper(isoMapper)
isoActor.GetProperty().SetColor(bisque)
isoActor.GetProperty().SetRepresentationToWireframe()
streamer = vtk.vtkStreamLine()
#    streamer SetInputConnection [reader GetOutputPort]
streamer.SetInputData(reader.GetOutput().GetBlock(0))
streamer.SetStartPosition(-1.2, -0.1, 1.3)
streamer.SetMaximumPropagationTime(500)
streamer.SetStepLength(0.05)
streamer.SetIntegrationStepLength(0.05)
streamer.SetIntegrationDirectionToIntegrateBothDirections()
streamTube = vtk.vtkTubeFilter()
streamTube.SetInputConnection(streamer.GetOutputPort())
streamTube.SetRadius(0.025)
streamTube.SetNumberOfSides(6)
streamTube.SetVaryRadius(VTK_VARY_RADIUS_BY_VECTOR)
mapStreamTube = vtk.vtkPolyDataMapper()
mapStreamTube.SetInputConnection(streamTube.GetOutputPort())
mapStreamTube.SetScalarRange(
示例#19
0
def read_vtk(name):
    import vtk
    import numpy

    gridreader = vtk.vtkXMLStructuredGridReader()
    gridreader.SetFileName(name)
    #gridreader.SetPointArrayStatus("Density",0)
    selection = gridreader.GetPointDataArraySelection()
    selection.DisableArray("Density")
    #selection.DisableArray("Velocity")
    selection.DisableArray("Phase")
    gridreader.Update()

    grid = gridreader.GetOutput()

    data = grid.GetPointData()
    points = grid.GetPoints()
    dims = grid.GetDimensions()
    #data.SetActiveScalars("Phase");
    data.SetActiveVectors("Velocity")
    #Create a contour
    contour = vtk.vtkContourFilter()
    contour.SetInputConnection(gridreader.GetOutputPort())
    contour.SetValue(0, 0.0)

    contourMapper = vtk.vtkPolyDataMapper()
    #contourMapper.SetScalarRange(phase.GetRange())
    contourMapper.SetInputConnection(contour.GetOutputPort())

    contourActor = vtk.vtkActor()
    contourActor.SetMapper(contourMapper)

    rake1 = vtk.vtkLineSource()
    rake1.SetPoint1(0, 0, 0)
    rake1.SetPoint2(0, 50, 0)
    rake1.SetResolution(21)
    rake1Mapper = vtk.vtkPolyDataMapper()
    rake1Mapper.SetInputConnection(rake1.GetOutputPort())
    rake1Actor = vtk.vtkActor()
    rake1Actor.SetMapper(rake1Mapper)

    rake2 = vtk.vtkLineSource()
    rake2.SetPoint1(0, 0, 850)
    rake2.SetPoint2(0, 50, 850)
    rake2.SetResolution(21)
    rake2Mapper = vtk.vtkPolyDataMapper()
    rake2Mapper.SetInputConnection(rake2.GetOutputPort())
    rake2Actor = vtk.vtkActor()
    rake2Actor.SetMapper(rake2Mapper)

    lines = vtk.vtkAppendPolyData()
    lines.AddInput(rake1.GetOutput())
    lines.AddInput(rake2.GetOutput())
    rk4 = vtk.vtkRungeKutta4()
    streamer = vtk.vtkStreamLine()
    streamer.SetInputConnection(gridreader.GetOutputPort())
    streamer.SetSource(lines.GetOutput())
    streamer.SetMaximumPropagationTime(100000)
    #streamer.GetStepLengthMinValue()=0.01
    #streamer.GetStepLengthMaxValue()=0.5
    #streamer.SetTerminalSpeed(1e-13)
    streamer.SetIntegrationStepLength(.2)
    streamer.SetStepLength(.2)
    #streamer.SetNumberOfThreads(1)
    streamer.SetIntegrationDirectionToIntegrateBothDirections()
    #streamer.VorticityOn()
    streamer.SetIntegrator(rk4)

    plane = vtk.vtkPlane()
    #plane.SetInput(grid)
    #plane.SetResolution(50, 50)
    plane.SetOrigin(25.0, 10.0, 0.0)
    plane.SetNormal(1.0, 0.0, 0.0)

    cutter = vtk.vtkCutter()
    cutter.SetCutFunction(plane)
    cutter.SetInput(grid)
    cutter.Update()

    cutterMapper = vtk.vtkPolyDataMapper()
    cutterMapper.SetInputConnection(cutter.GetOutputPort(0))

    # Create plane actor
    planeActor = vtk.vtkActor()
    planeActor.GetProperty().SetColor(1.0, 1, 0)
    planeActor.GetProperty().SetLineWidth(2)
    planeActor.SetMapper(cutterMapper)

    #transP1 = vtk.vtkTransform()
    #transP1.Translate(3.7, 0.0, 28.37)
    #transP1.Scale(5, 5, 5)
    #transP1.RotateY(90)
    #tpd1 = vtk.vtkTransformPolyDataFilter()
    #tpd1.SetInputConnection(plane.GetOutputPort())
    #tpd1.SetTransform(transP1)
    #tpd1Actor.GetProperty().SetColor(0, 0, 0)

    #lineWidget = vtk.vtkLineWidget()
    #seeds = vtk.vtkPolyData()
    #lineWidget.SetInput(grid)
    #lineWidget.SetAlignToYAxis()
    #lineWidget.PlaceWidget()
    #lineWidget.GetPolyData(seeds)
    #lineWidget.ClampToBoundsOn()

    streamMapper = vtk.vtkPolyDataMapper()
    streamMapper.SetInputConnection(streamer.GetOutputPort())
    #streamMapper.SetScalarRange(data.GetOutput().GetScalarRange())
    streamActor = vtk.vtkActor()
    streamActor.SetMapper(streamMapper)
    streamActor.VisibilityOn()

    #Create the outline
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(gridreader.GetOutputPort())

    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInputConnection(outline.GetOutputPort())

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

    # Create the Renderer, RenderWindow, and RenderWindowInteractor
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Add the actors to the render; set the background and size
    #ren.AddActor(contourActor)
    #ren.AddActor(outlineActor)
    ren.AddActor(streamActor)
    #ren.AddActor(rake1Actor)
    #ren.AddActor(rake2Actor)
    #ren.AddActor(planeActor)h=streamline(vz,vy,sz,sy,[0.1, 15000])
    #ren.SetBackground(1.0,1.0,1.0)
    ren.SetBackground(0.1, 0.2, 0.4)

    renWin.SetSize(500, 500)

    # Zoom in closer
    #ren.ResetCamera()
    cam1 = ren.GetActiveCamera()
    cam1.SetPosition(1000, 0, 500)
    cam1.SetFocalPoint(0, 0, 500)

    iren.Initialize()
    renWin.Render()
    iren.Start()
示例#20
0
def read_vtk_2d(name):
    import vtk
    import numpy

    gridreader = vtk.vtkXMLStructuredGridReader()
    gridreader.SetFileName(name)
    #gridreader.SetPointArrayStatus("Density",0)
    selection = gridreader.GetPointDataArraySelection()
    selection.DisableArray("Density")
    #selection.DisableArray("Velocity")
    #selection.DisableArray("Phase")
    gridreader.Update()

    grid = gridreader.GetOutput()

    data = grid.GetPointData()
    points = grid.GetPoints()
    dims = grid.GetDimensions()
    #data.SetActiveScalars("Phase");
    data.SetActiveVectors("Velocity")
    velocity = data.GetArray("Velocity")
    phase = data.GetArray("Phase")

    vel_image = vtk.vtkImageData()
    vel_image.SetDimensions(dims[1], dims[2], 1)
    vel_image.SetSpacing(1.0, 1.0, 1.0)
    vel_image.SetOrigin(0.0, 0.0, 0.0)

    Array = vtk.vtkDoubleArray()
    Array.SetNumberOfComponents(3)
    Array.SetNumberOfTuples(points.GetNumberOfPoints())
    Array.Initialize()
    Array.SetName("VelocitySlice")

    ArrayPhase = vtk.vtkDoubleArray()
    ArrayPhase.SetNumberOfComponents(1)
    ArrayPhase.SetNumberOfTuples(points.GetNumberOfPoints())
    ArrayPhase.Initialize()
    ArrayPhase.SetName("PhaseSlice")

    for counter in range(0, 10):
        print points.GetPoint(counter)
    raw_input()
    exam = 1
    print dims[0], dims[1], dims[2]
    #raw_input()
    for counter in range(0, vel_image.GetNumberOfPoints()):
        x, y, z = vel_image.GetPoint(counter)
        counter_big = y * dims[0] * dims[1] + x * dims[0] + exam
        #print x,y,z
        #print counter_big

        vz = velocity.GetTuple3(counter_big)[2]
        vy = velocity.GetTuple3(counter_big)[1]
        phase_value = phase.GetTuple1(counter_big)
        Array.InsertNextTuple3(vy, vz, 0.0)
        ArrayPhase.InsertNextTuple1(phase_value)
        #if phase_value<0.0:
        #    print phase_value

    vel_image.GetPointData().SetVectors(Array)
    vel_image.GetPointData().SetScalars(ArrayPhase)
    vel_image.GetPointData().SetActiveScalars("PhaseSlice")
    vel_image.GetPointData().SetActiveVectors("VelocitySlice")
    print vel_image.GetPointData().GetArray("PhaseSlice")
    vel_image.Update()

    contour = vtk.vtkContourFilter()
    contour.SetInput(vel_image)
    #contour.SetValue(0,0.0)

    contourMapper = vtk.vtkPolyDataMapper()
    #contourMapper.SetScalarRange(phase.GetRange())
    contourMapper.SetInputConnection(contour.GetOutputPort())
    #contourMapper.SetColorMode

    contourActor = vtk.vtkActor()
    contourActor.SetMapper(contourMapper)

    #contourActor.SetColor(0.0,0.1,0.2)

    rk4 = vtk.vtkRungeKutta4()
    line = vtk.vtkLineSource()
    line.SetPoint1(50, 0, 0)
    line.SetPoint2(0, 0, 0)
    line.SetResolution(21)
    streamer = vtk.vtkStreamLine()
    streamer.SetInput(vel_image)
    streamer.SetSource(line.GetOutput())
    streamer.SetMaximumPropagationTime(300000)
    #streamer.GetStepLengthMinValue()=0.01
    #streamer.GetStepLengthMaxValue()=0.5
    #streamer.SetTerminalSpeed(1e-13)
    streamer.SetIntegrationStepLength(.2)
    streamer.SetStepLength(.5)
    #streamer.SetNumberOfThreads(1)
    streamer.SetIntegrationDirectionToIntegrateBothDirections()
    #streamer.VorticityOn()
    streamer.SetIntegrator(rk4)

    streamMapper = vtk.vtkPolyDataMapper()
    streamMapper.SetInputConnection(streamer.GetOutputPort())
    #streamMapper.SetScalarRange(data.GetOutput().GetScalarRange())
    streamActor = vtk.vtkActor()
    streamActor.SetMapper(streamMapper)
    streamActor.VisibilityOn()

    # Create the Renderer, RenderWindow, and RenderWindowInteractor
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Add the actors to the render; set the background and size
    ren.AddActor(streamActor)
    ren.AddActor(contourActor)
    #ren.SetBackground(1.0,1.0,1.0)
    ren.SetBackground(0.1, 0.2, 0.4)

    renWin.SetSize(500, 500)

    #ren.ResetCamera()
    #cam1 = ren.GetActiveCamera()
    #cam1.SetPosition(1000,0,500)
    #cam1.SetFocalPoint(0,0,500)

    iren.Initialize()
    renWin.Render()
    iren.Start()
示例#21
0

#	Calculating starting point of particles
dims = reader.GetOutput().GetExtent()
cy = (dims[3] - dims[2]) / 4.0
cz = (dims[5] - dims[4]) / 2.0


#	Creation of patricle source 1
particle_source = vtk.vtkPointSource()
particle_source.SetCenter(0, cy, cz)
particle_source.SetRadius(radius)
particle_source.SetNumberOfPoints(num_points)

#	Add streamlines from pointsource
stream_lines = vtk.vtkStreamLine()
stream_lines.SetInputConnection(reader.GetOutputPort())
stream_lines.SetSourceConnection(particle_source.GetOutputPort())
stream_lines.SetStepLength(step_len)
stream_lines.SetMaximumPropagationTime(prop_time)
stream_lines.SetTerminalSpeed(0.05)
stream_lines.SetIntegrationDirectionToForward()

#	Add tube around streamlines
tube_filter = vtk.vtkTubeFilter()
tube_filter.SetInputConnection(stream_lines.GetOutputPort())
tube_filter.SetVaryRadiusToVaryRadiusByVector()
tube_filter.CappingOn()
tube_filter.SetNumberOfSides(10)

#	Map data, set coloring through scalar off
def main(vector_file, magnitude_file):

    num_critical_points = 6
    CriticalPoints = vtk.vtkPoints()

    CriticalPoints.InsertNextPoint(35, 14, 20)
    CriticalPoints.InsertNextPoint(55, 15, 20)
    CriticalPoints.InsertNextPoint(65, 45, 19)
    CriticalPoints.InsertNextPoint(45, 44.8, 20)
    CriticalPoints.InsertNextPoint(20, 29.7, 19.8)
    CriticalPoints.InsertNextPoint(10, 32.2, 16.1)

    ColorRange = vtk.vtkLookupTable()
    ColorRange.SetTableRange(0, 1)
    ColorRange.SetHueRange(0, 1)
    ColorRange.SetSaturationRange(1, 1)
    ColorRange.SetAlphaRange(0.3, 0.5)
    ColorRange.Build()

    reader = vtk.vtkStructuredPointsReader()
    reader.SetFileName(vector_file)
    reader.Update()

    mags = reader.GetOutput()

    range1 = mags.GetScalarRange()
    v0 = range1[0]
    v1 = range1[1]

    reader_magnitude = vtk.vtkStructuredPointsReader()
    reader_magnitude.SetFileName(magnitude_file)
    reader_magnitude.Update()

    # All entities initialized equal to number of critical points
    sphere1, stream1, scalarSurface1, tube1, dataMapper1, dataActor1, criticalMarker1, criticalMapper1, criticalActor1, probe1, mask1, glyph1, glyphMapper1, glyphActor1, plane1 = (
        [],
        [],
        [],
        [],
        [],
        [],
        [],
        [],
        [],
        [],
        [],
        [],
        [],
        [],
        [],
    )
    for i in range(0, num_critical_points):
        sphere1.append(vtk.vtkSphereSource())
        stream1.append(vtk.vtkStreamLine())
        scalarSurface1.append(vtk.vtkRuledSurfaceFilter())
        tube1.append(vtk.vtkTubeFilter())
        dataMapper1.append(vtk.vtkPolyDataMapper())
        dataActor1.append(vtk.vtkActor())

        criticalMarker1.append(vtk.vtkSphereSource())
        criticalMapper1.append(vtk.vtkPolyDataMapper())
        criticalActor1.append(vtk.vtkActor())

        probe1.append(vtk.vtkProbeFilter())
        mask1.append(vtk.vtkMaskPoints())
        glyph1.append(vtk.vtkGlyph3D())
        glyphMapper1.append(vtk.vtkPolyDataMapper())
        glyphActor1.append(vtk.vtkActor())

        plane1.append(vtk.vtkPlaneSource())

    integ = vtk.vtkRungeKutta4()

    cone = vtk.vtkConeSource()
    cone.SetResolution(8)
    cone.SetHeight(1.0)
    cone.SetRadius(0.2)

    transform = vtk.vtkTransform()
    transform.Translate(0, 0, 0)

    transformFilter = vtk.vtkTransformPolyDataFilter()
    transformFilter.SetInput(cone.GetOutput())
    transformFilter.SetTransform(transform)

    outline = vtk.vtkOutlineFilter()
    outline.SetInput(reader.GetOutput())

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

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

    bar = vtk.vtkScalarBarActor()
    bar.SetLookupTable(ColorRange)

    renderer = vtk.vtkRenderer()

    for i in range(0, num_critical_points):
        sphere1[i].SetRadius(2)
        sphere1[i].SetCenter(
            CriticalPoints.GetPoint(i)[0], CriticalPoints.GetPoint(i)[1], CriticalPoints.GetPoint(i)[2]
        )
        sphere1[i].SetThetaResolution(1)
        stream1[i].SetInput(reader.GetOutput())
        stream1[i].SetSource(sphere1[i].GetOutput())
        stream1[i].SetIntegrator(integ)
        stream1[i].SetMaximumPropagationTime(500)
        stream1[i].SetIntegrationStepLength(0.1)
        stream1[i].SetIntegrationDirectionToIntegrateBothDirections()
        stream1[i].SetStepLength(0.1)

        scalarSurface1[i].SetInput(stream1[i].GetOutput())
        scalarSurface1[i].SetOffset(0)
        scalarSurface1[i].SetOnRatio(2)
        scalarSurface1[i].PassLinesOn()
        scalarSurface1[i].SetRuledModeToPointWalk()
        scalarSurface1[i].SetDistanceFactor(50)

        tube1[i].SetInput(scalarSurface1[i].GetOutput())
        tube1[i].SetRadius(0.1)
        tube1[i].SetNumberOfSides(6)

        dataMapper1[i].SetInput(tube1[i].GetOutput())
        dataMapper1[i].SetScalarRange(v0, v1)
        dataMapper1[i].SetLookupTable(ColorRange)

        dataActor1[i].SetMapper(dataMapper1[i])
        # renderer.AddActor(dataActor1[i])

        criticalMarker1[i].SetRadius(1.0)
        criticalMarker1[i].SetCenter(
            CriticalPoints.GetPoint(i)[0], CriticalPoints.GetPoint(i)[1], CriticalPoints.GetPoint(i)[2]
        )
        criticalMarker1[i].SetThetaResolution(10)
        criticalMapper1[i].SetInput(criticalMarker1[i].GetOutput())

        criticalActor1[i].SetMapper(criticalMapper1[i])
        criticalActor1[i].GetProperty().SetColor(1, 1, 0)
        criticalActor1[i].GetProperty().SetOpacity(0.5)
        # renderer.AddActor(criticalActor1[i])

        probe1[i].SetInput(stream1[i].GetOutput())
        probe1[i].SetSource(reader.GetOutput())

        mask1[i].SetInput(probe1[i].GetOutput())
        mask1[i].SetOnRatio(60)
        mask1[i].RandomModeOn()

        glyph1[i].SetInput(mask1[i].GetOutput())
        glyph1[i].SetSource(transformFilter.GetOutput())
        glyph1[i].SetScaleModeToScaleByVector()
        glyph1[i].SetScaleFactor(2)
        glyph1[i].SetVectorModeToUseVector()
        glyph1[i].SetColorModeToColorByVector()

        glyphMapper1[i].SetInput(glyph1[i].GetOutput())
        glyphMapper1[i].SetLookupTable(ColorRange)

        glyphActor1[i].SetMapper(glyphMapper1[i])
        # renderer.AddActor(glyphActor1[i])

    # removeActors1(renderer, dataActor, criticalActor, glyphActor, dataActor1, criticalActor1, glyphActor1)

    mags = reader.GetOutput()
    bounds = mags.GetBounds()
    x0 = bounds[0]
    x1 = bounds[1]
    y0 = bounds[2]
    y1 = bounds[3]
    z0 = bounds[4]
    z1 = bounds[5]

    range1 = mags.GetScalarRange()
    v0 = range1[0]
    v1 = range1[1]

    plane1[0].SetOrigin(x0, y0, z0)
    plane1[0].SetPoint1(x0, y1, z0)
    plane1[0].SetPoint2(x0, y0, z1)

    plane1[1].SetOrigin(x0, y0, z0)
    plane1[1].SetPoint1(x0, y1, z0)
    plane1[1].SetPoint2(x1, y0, z0)

    plane1[2].SetOrigin(x0, y0, z0)
    plane1[2].SetPoint1(x0, y0, z1)
    plane1[2].SetPoint2(x1, y0, z0)

    plane1[3].SetOrigin(x1, y1, z1)
    plane1[3].SetPoint1(x1, y1, z0)
    plane1[3].SetPoint2(x1, y0, z1)

    plane1[4].SetOrigin(x1, y1, z1)
    plane1[4].SetPoint1(x0, y1, z1)
    plane1[4].SetPoint2(x1, y1, z0)

    plane1[5].SetOrigin(x1, y1, z1)
    plane1[5].SetPoint1(x0, y1, z1)
    plane1[5].SetPoint2(x1, y1, z0)

    for i in range(0, num_critical_points):
        plane1[i].SetResolution(5, 5)
        stream1[i].SetSource(plane1[i].GetOutput())
        renderer.AddActor(dataActor1[i])
        renderer.AddActor(glyphActor1[i])
        glyph1[i].SetScaleFactor(4)

    renderer.AddActor(bar)
    renderer.AddActor(outlineActor)

    for i in range(0, num_critical_points):
        renderer.AddActor(criticalActor1[i])

    renderer_window = vtk.vtkRenderWindow()
    renderer_window.AddRenderer(renderer)
    renderer_window.SetSize(512, 512)

    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderer_window)

    style = vtk.vtkInteractorStyleTrackballCamera()
    interactor.SetInteractorStyle(style)

    renderer.AddActor(bar)

    renderer.AddActor(outlineActor)

    renderer_window.Render()
    interactor.Start()
示例#23
0
def Main():
    global isovalue, contours, ren
    
    # Create the RenderWindow, Renderer and both Actors
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.SetMultiSamples(0)
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    iren.RemoveObservers('RightButtonPressEvent')
    iren.AddObserver('RightButtonPressEvent', print_camera_settings, 1.0)
    iren.AddObserver('RightButtonPressEvent', after_print_camera_settings, -1.0)

    print "data: %s %s %s" % (sys.argv[1], sys.argv[2], sys.argv[3])
    
    cfdreader = vtk.vtkStructuredPointsReader()
    cfdreader.SetFileName(sys.argv[1])
    
    # setup wing data
    wingReader = vtk.vtkUnstructuredGridReader()
    wingReader.SetFileName(sys.argv[3])
    wingReader.Update()
    wingMapper = vtk.vtkDataSetMapper()
    wingMapper.SetInputConnection(wingReader.GetOutputPort())
    wingActor = vtk.vtkActor()
    wingActor.SetMapper(wingMapper)
    wingActor.GetProperty().SetColor(.4, .4, .4)
    
    bRakesToActor = [True, True, False]
    bWingToActor = True
    
    datamin = 0
    datamax = 230
    
    lut = vtk.vtkColorTransferFunction()
    lut.SetColorSpaceToHSV()
    lut.AddHSVPoint(datamin, 0, 1, 1)
    dis = float(datamax - datamin) / 7
    for i in range(0, 8):
        lut.AddHSVPoint(float(datamin + dis * i), 0.1 * i, 1, 1)
    
    colorBar = vtk.vtkScalarBarActor()
    colorBar.SetLookupTable(lut)
    colorBar.SetTitle("")
    colorBar.SetNumberOfLabels(6)
    colorBar.SetLabelFormat("%4.0f")
    colorBar.SetPosition(0.9, 0.1)
    colorBar.SetWidth(0.05)
    colorBar.SetHeight(0.4)
    ren.AddActor(colorBar)
    
    rakes = [
             vtk.vtkLineSource(),
             vtk.vtkLineSource(),
             vtk.vtkLineSource()
             ]
    rakes[0].SetPoint1(-230, -230, 0)
    rakes[0].SetPoint2(230, 230, 0)
    rakes[0].SetResolution(50)
    
    rakes[1].SetPoint1(230, -230, 0)
    rakes[1].SetPoint2(-230, 230, 0)
    rakes[1].SetResolution(50)
    
    rakes[2].SetPoint1(0, -100, 10)
    rakes[2].SetPoint2(0, 100, 10)
    rakes[2].SetResolution(60)
    
    rakeColors = [
                  [0, 1, 0],
                  [0, 1, 0],
                  [0, 1, 0],
                  ]
    
    for i in range(0, len(rakes)):
        integ = vtk.vtkRungeKutta4()
        streamLine = vtk.vtkStreamLine()
        streamLine.SetInputConnection(cfdreader.GetOutputPort())
        streamLine.SetSourceConnection(rakes[i].GetOutputPort())
        streamLine.SetMaximumPropagationTime(50);
        streamLine.SetIntegrationStepLength(1);
        streamLine.SetStepLength(0.01);
        streamLine.SetIntegrationDirectionToForward();
        streamLine.SetIntegrator(integ)
        streamLine.SpeedScalarsOn()
        
        streamLineMapper = vtk.vtkPolyDataMapper()
        streamLineMapper.SetInputConnection(streamLine.GetOutputPort())
        streamLineMapper.SetLookupTable(lut)
        
        streamLineActor = vtk.vtkActor()
        streamLineActor.SetMapper(streamLineMapper)
        streamLineActor.GetProperty().SetColor(rakeColors[i])
        streamLineActor.GetProperty().SetOpacity(0.9);
        
        if bRakesToActor[i]:
            ren.AddActor(streamLineActor)
 
    if bWingToActor:
        ren.AddActor(wingActor)
    
    isoreader = vtk.vtkStructuredPointsReader()
    isoreader.SetFileName(sys.argv[2])
    isoreader.Update()
    
#     r = isoreader.GetOutput().GetScalarRange()
#     datamin = r[0]
#     datamax = r[1]
#     isovalue = (datamax+datamin)/2.0
    isovalue = 300
    datamin = 0
    datamax = 300
    
    contours = vtk.vtkContourFilter()
    contours.SetInputConnection(isoreader.GetOutputPort());
    contours.ComputeNormalsOn()
    contours.SetValue(0, isovalue)
    
    lut = vtk.vtkColorTransferFunction()
    lut.SetColorSpaceToHSV()
    lut.AddHSVPoint(datamin, 0, 1, 1)
    dis = (datamax - datamin) / 7
    for i in range(0, 8):
        lut.AddHSVPoint(datamin + dis * i, 0.1 * i, 1, 1)
        
    isoMapper = vtk.vtkPolyDataMapper()
    isoMapper.SetLookupTable(lut)
    isoMapper.SetInputConnection(contours.GetOutputPort())

    isoActor = vtk.vtkActor()
    isoActor.GetProperty().SetRepresentationToWireframe()
    isoActor.SetMapper(isoMapper)
    isoActor.GetProperty().SetOpacity(0.08);

    ren.AddActor(wingActor)
    ren.AddActor(isoActor)
    
    ren.SetBackground(0, 0, 0)
    renWin.SetSize(1600, 900)
    
    isovalueSlider = vtk.vtkSliderRepresentation2D()
    isovalueSlider.SetMinimumValue(datamin)
    isovalueSlider.SetMaximumValue(datamax)
    isovalueSlider.SetValue(isovalue)
    isovalueSlider.SetTitleText("isovalue")
    isovalueSlider.GetPoint1Coordinate().SetCoordinateSystemToNormalizedDisplay()
    isovalueSlider.GetPoint1Coordinate().SetValue(0.0, 0.4)
    isovalueSlider.GetPoint2Coordinate().SetCoordinateSystemToNormalizedDisplay()
    isovalueSlider.GetPoint2Coordinate().SetValue(0.2, 0.4)
    isovalueSlider.SetSliderLength(0.02)
    isovalueSlider.SetSliderWidth(0.03)
    isovalueSlider.SetEndCapLength(0.01)
    isovalueSlider.SetEndCapWidth(0.03)
    isovalueSlider.SetTubeWidth(0.005)
    isovalueSlider.SetLabelFormat("%3.0lf")
    isovalueSlider.SetTitleHeight(0.02)
    isovalueSlider.SetLabelHeight(0.02)
    SliderWidget1 = vtk.vtkSliderWidget()
    SliderWidget1.SetInteractor(iren)
    SliderWidget1.SetRepresentation(isovalueSlider)
    SliderWidget1.KeyPressActivationOff()
    SliderWidget1.SetAnimationModeToAnimate()
    SliderWidget1.SetEnabled(False)
    SliderWidget1.AddObserver("InteractionEvent", isovalueSliderHandler)
    
    ren.ResetCamera()
    ren.GetActiveCamera().SetClippingRange(417.55784439078775, 1491.5763714138557)
    ren.GetActiveCamera().SetFocalPoint(118.72183980792761, 0.00012969970703125, 36.469017028808594)
    ren.GetActiveCamera().SetPosition(680.0192576650034, 16.65944318371372, 790.5781258299678)
    ren.GetActiveCamera().SetViewUp(-0.802117714199773, -0.005112780752923929, 0.5971440630533839)

    # Render
    iren.Initialize()
    renWin.Render()
    iren.Start()