コード例 #1
0
def CreateAxes():
    global xAxis, yAxis, zAxis, popSplatter

    # Create axes.
    popSplatter.Update()
    bounds = popSplatter.GetOutput().GetBounds()
    axes = vtk.vtkAxes()
    axes.SetOrigin(bounds[0], bounds[2], bounds[4])
    axes.SetScaleFactor(popSplatter.GetOutput().GetLength()/5.0)

    axesTubes = vtk.vtkTubeFilter()
    axesTubes.SetInputConnection(axes.GetOutputPort())
    axesTubes.SetRadius(axes.GetScaleFactor()/25.0)
    axesTubes.SetNumberOfSides(6)

    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInputConnection(axesTubes.GetOutputPort())

    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)

    # Label the axes.
    XText = vtk.vtkVectorText()
    XText.SetText(xAxis)

    XTextMapper = vtk.vtkPolyDataMapper()
    XTextMapper.SetInputConnection(XText.GetOutputPort())

    XActor = vtk.vtkFollower()
    XActor.SetMapper(XTextMapper)
    XActor.SetScale(0.02, .02, .02)
    XActor.SetPosition(0.35, -0.05, -0.05)
    XActor.GetProperty().SetColor(0, 0, 0)

    YText = vtk.vtkVectorText()
    YText.SetText(yAxis)

    YTextMapper = vtk.vtkPolyDataMapper()
    YTextMapper.SetInputConnection(YText.GetOutputPort())

    YActor = vtk.vtkFollower()
    YActor.SetMapper(YTextMapper)
    YActor.SetScale(0.02, .02, .02)
    YActor.SetPosition(-0.05, 0.35, -0.05)
    YActor.GetProperty().SetColor(0, 0, 0)

    ZText = vtk.vtkVectorText()
    ZText.SetText(zAxis)

    ZTextMapper = vtk.vtkPolyDataMapper()
    ZTextMapper.SetInputConnection(ZText.GetOutputPort())

    ZActor = vtk.vtkFollower()
    ZActor.SetMapper(ZTextMapper)
    ZActor.SetScale(0.02, .02, .02)
    ZActor.SetPosition(-0.05, -0.05, 0.35)
    ZActor.GetProperty().SetColor(0, 0, 0)
    return axesActor, XActor, YActor, ZActor
コード例 #2
0
def CreateAxes():
    global xAxis, yAxis, zAxis, popSplatter

    # Create axes.
    popSplatter.Update()
    bounds = popSplatter.GetOutput().GetBounds()
    axes = vtk.vtkAxes()
    axes.SetOrigin(bounds[0], bounds[2], bounds[4])
    axes.SetScaleFactor(popSplatter.GetOutput().GetLength()/5.0)

    axesTubes = vtk.vtkTubeFilter()
    axesTubes.SetInputConnection(axes.GetOutputPort())
    axesTubes.SetRadius(axes.GetScaleFactor()/25.0)
    axesTubes.SetNumberOfSides(6)

    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInputConnection(axesTubes.GetOutputPort())

    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)

    # Label the axes.
    XText = vtk.vtkVectorText()
    XText.SetText(xAxis)

    XTextMapper = vtk.vtkPolyDataMapper()
    XTextMapper.SetInputConnection(XText.GetOutputPort())

    XActor = vtk.vtkFollower()
    XActor.SetMapper(XTextMapper)
    XActor.SetScale(0.02, .02, .02)
    XActor.SetPosition(0.35, -0.05, -0.05)
    XActor.GetProperty().SetColor(0, 0, 0)

    YText = vtk.vtkVectorText()
    YText.SetText(yAxis)

    YTextMapper = vtk.vtkPolyDataMapper()
    YTextMapper.SetInputConnection(YText.GetOutputPort())

    YActor = vtk.vtkFollower()
    YActor.SetMapper(YTextMapper)
    YActor.SetScale(0.02, .02, .02)
    YActor.SetPosition(-0.05, 0.35, -0.05)
    YActor.GetProperty().SetColor(0, 0, 0)

    ZText = vtk.vtkVectorText()
    ZText.SetText(zAxis)

    ZTextMapper = vtk.vtkPolyDataMapper()
    ZTextMapper.SetInputConnection(ZText.GetOutputPort())

    ZActor = vtk.vtkFollower()
    ZActor.SetMapper(ZTextMapper)
    ZActor.SetScale(0.02, .02, .02)
    ZActor.SetPosition(-0.05, -0.05, 0.35)
    ZActor.GetProperty().SetColor(0, 0, 0)
    return axesActor, XActor, YActor, ZActor
コード例 #3
0
ファイル: vtkPlot.py プロジェクト: gouarin/python_azur
 def showAxis(self):
     if self.axis:
         xmin, xmax, ymin, ymax, zmin, zmax = self.bounds[:]
         axes=vtk.vtkAxes()
         axes.SetOrigin(0.0,0.0,0.0)
         axes.SetScaleFactor(0.1*max([xmax-xmin,ymax-ymin,zmax-zmin]))
         axesTubes=vtk.vtkTubeFilter()
         axesTubes.SetInputConnection(axes.GetOutputPort())
         axesTubes.SetRadius(0.2)
         axesTubes.SetNumberOfSides(6)
         axesMapper=vtk.vtkPolyDataMapper() 
         axesMapper.SetInputConnection(axesTubes.GetOutputPort())
         axesActor=vtk.vtkActor() 
         axesActor.SetMapper(axesMapper)
         XText=vtk.vtkVectorText()    
         XText.SetText("X")
         XTextMapper=vtk.vtkPolyDataMapper() 
         XTextMapper.SetInputConnection(XText.GetOutputPort())
         XActor=vtk.vtkFollower()
         XActor.SetMapper(XTextMapper)
         XActor.SetScale(2.0, 2.0, 2.0)
         XActor.SetPosition(1.11*xmax, ymin, zmin)
         XActor.GetProperty().SetColor(0,0,0)
         XActor.SetCamera(self.cam)
         YText=vtk.vtkVectorText()    
         YText.SetText("Y")
         YTextMapper=vtk.vtkPolyDataMapper() 
         YTextMapper.SetInputConnection(YText.GetOutputPort())
         YActor=vtk.vtkFollower()
         YActor.SetMapper(YTextMapper)
         YActor.SetScale(2.0, 2.0, 2.0)
         YActor.SetPosition(xmin, 1.11*ymax, zmin)
         YActor.GetProperty().SetColor(0,0,0)
         YActor.SetCamera(self.cam)
         ZText=vtk.vtkVectorText()    
         ZText.SetText("Z")
         ZTextMapper=vtk.vtkPolyDataMapper() 
         ZTextMapper.SetInputConnection(ZText.GetOutputPort())
         ZActor=vtk.vtkFollower()
         ZActor.SetMapper(ZTextMapper)
         ZActor.SetScale(2.0, 2.0, 2.0)
         ZActor.SetPosition(xmin, ymin, 1.11*zmax)
         ZActor.GetProperty().SetColor(0,0,0)
         ZActor.SetCamera(self.cam)
         self.ren.AddActor(axesActor)
         self.ren.AddActor(XActor)
         self.ren.AddActor(YActor)
         self.ren.AddActor(ZActor)
コード例 #4
0
    def initArea(self):
        # Zoom items
        self.zitems = []
        
        self.cellTypeActors={}
        self.outlineActor = vtk.vtkActor()
        self.outlineDim=[0,0,0]
        
        self.invisibleCellTypes={}
        self.typesInvisibleStr=""
        self.set3DInvisibleTypes()
        
        axesActor = vtk.vtkActor()
        axisTextActor = vtk.vtkFollower()
        
        self.clut = vtk.vtkLookupTable()
        self.clut.SetHueRange(0.67, 0.0)
        self.clut.SetSaturationRange(1.0,1.0)
        self.clut.SetValueRange(1.0,1.0)
        self.clut.SetAlphaRange(1.0,1.0)
        self.clut.SetNumberOfColors(1024)
        self.clut.Build()

        ## Set up the mapper and actor (3D) for concentration field.
        # self.conMapper = vtk.vtkPolyDataMapper()
        self.conActor = vtk.vtkActor()

        self.glyphsActor=vtk.vtkActor()
        # self.glyphsMapper=vtk.vtkPolyDataMapper()
        
        self.cellGlyphsActor  = vtk.vtkActor()
        self.FPPLinksActor  = vtk.vtkActor()

        # Weird attributes
        self.typeActors             = {} # vtkActor
コード例 #5
0
    def add_ring_actor(self, marker):
        ringActor = RingActor(marker, self.pw, lineWidth=self.defaultRingLine)
        vis = ringActor.update()
        self.renderer.AddActor(ringActor)
        self.ringActors.AddItem(ringActor)


        # a hack to keep vtk from casting my class when I put it in
        # the collection.  If I don't register some func, I lose all
        # the derived methods        
        self.observer.AddObserver('EndInteractionEvent', ringActor.silly_hack)

        text = vtk.vtkVectorText()
        text.SetText(marker.get_label())
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInput(text.GetOutput())

        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        size = 2*marker.get_size()
        textActor.SetScale(size, size, size)
        x,y,z = marker.get_center()
        textActor.SetPosition(x, y, z)
        textActor.SetCamera(self.camera)
        textActor.GetProperty().SetColor(marker.get_label_color())
        if EventHandler().get_labels_on() and vis:
            textActor.VisibilityOn()
        else:
            textActor.VisibilityOff()

        self.textActors[marker] = textActor
        self.renderer.AddActor(textActor)
コード例 #6
0
    def _build_planet_actors(self, key: str, Center: np.array(3),
                             radius: float, color: str):
        sphereSource = vtk.vtkSphereSource()
        # Make the surface smooth.
        sphereSource.SetPhiResolution(100)
        sphereSource.SetThetaResolution(100)
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(sphereSource.GetOutputPort())

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetColor(Colors.GetColor3d(color))
        sphereSource.SetCenter(Center[0], Center[1], Center[2])
        sphereSource.SetRadius(radius)

        # 标签
        vText = vtkVectorText()
        vText.SetText(key)
        textMapper = vtkPolyDataMapper()
        textMapper.SetInputConnection(vText.GetOutputPort())
        textActor = vtkFollower()
        textActor.SetMapper(textMapper)
        textActor.SetScale(0.05)
        # textActor.AddPosition(Center[0], Center[1], Center[2])
        textActor.SetPosition(Center[0], Center[1], Center[2])
        textActor.SetCamera(self.vtkWidget.renderer.GetActiveCamera())

        # 加入数据集
        self.dataProvider.add_sphere_source(key, sphereSource, textActor)
        self.vtkWidget.renderer.AddActor(actor)
        self.vtkWidget.renderer.AddActor(textActor)
        return
コード例 #7
0
ファイル: Stocks1.py プロジェクト: moezb/opensimQt
def AddStock(renderers, apf, filename, name, zPosition):
    print("Adding", name)

    # Read the data
    PolyDataRead = vtk.vtkPolyDataReader()
    PolyDataRead.SetFileName(filename)
    PolyDataRead.Update()

    TubeFilter = vtk.vtkTubeFilter()
    TubeFilter.SetInputConnection(PolyDataRead.GetOutputPort())
    TubeFilter.SetNumberOfSides(8)
    TubeFilter.SetRadius(0.5)
    TubeFilter.SetRadiusFactor(10000)

    Transform = vtk.vtkTransform()
    Transform.Translate(0, 0, zPosition)
    Transform.Scale(0.15, 1, 1)

    TransformFilter = vtk.vtkTransformPolyDataFilter()
    TransformFilter.SetInputConnection(TubeFilter.GetOutputPort())
    TransformFilter.SetTransform(Transform)

    apf.AddInputData(TransformFilter.GetOutput())

    # Create the labels.
    TextSrc = vtk.vtkVectorText()
    TextSrc.SetText(name)
    numberOfPoints = PolyDataRead.GetOutput().GetNumberOfPoints()

    nameIndex = int((numberOfPoints - 1) * 0.8)

    nameLocation = PolyDataRead.GetOutput().GetPoint(nameIndex)

    x = nameLocation[0] * 0.15
    y = nameLocation[1] + 5.0
    z = zPosition

    for r in range(0, len(renderers)):
        LabelMapper = vtk.vtkPolyDataMapper()
        LabelMapper.SetInputConnection(TextSrc.GetOutputPort())

        LabelActor = vtk.vtkFollower()
        LabelActor.SetMapper(LabelMapper)
        LabelActor.SetPosition(x, y, z)
        LabelActor.SetScale(2, 2, 2)
        LabelActor.SetOrigin(TextSrc.GetOutput().GetCenter())

        # Increment zPosition.
        zPosition += 8.0

        StockMapper = vtk.vtkPolyDataMapper()
        StockMapper.SetInputConnection(TransformFilter.GetOutputPort())
        StockMapper.SetScalarRange(0, 8000)
        StockActor = vtk.vtkActor()
        StockActor.SetMapper(StockMapper)

        renderers[r].AddActor(StockActor)
        renderers[r].AddActor(LabelActor)
        LabelActor.SetCamera(renderers[r].GetActiveCamera())
    return zPosition
コード例 #8
0
    def add_marker(self, marker):
        print "PlaneWidgetsXYZ.add_marker(): self.renderer.AddActor(marker)"
        self.renderer.AddActor(marker)

        text = vtk.vtkVectorText()
        text.SetText(marker.get_label())
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInput(text.GetOutput())

        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        size = marker.get_size()
        textActor.SetScale(size, size, size)
        x,y,z = marker.get_center()
        textActor.SetPosition(x+size, y+size, z+size)
        textActor.SetCamera(self.camera)
        textActor.GetProperty().SetColor(marker.get_label_color())
        if EventHandler().get_labels_on():
            print "VisibilityOn"
            textActor.VisibilityOn()
        else:
            print "VisibilityOff"
            textActor.VisibilityOff()


        self.textActors[marker] = textActor
        print "PlaneWidgetsXYZ.add_marker(): self.renderer.AddActor(textActor)"
        self.renderer.AddActor(textActor)
コード例 #9
0
    def __init__(self,
                 text,
                 position=(0, 0, 0),
                 follow_cam=True,
                 scale=1,
                 color=None,
                 opacity=None,
                 fig="gcf"):
        super().__init__(fig)
        # Create the 3D text and the associated mapper and follower (a type of
        # actor). Position the text so it is displayed over the origin of the
        # axes.

        self.source = vtk.vtkVectorText()
        self.text = text

        # This chunk is different to how most plots objects construct
        # themselves. So super().add_to_plot() wont work unfortunately.

        self.actor = vtk.vtkFollower()
        self.scale = scale
        self.position = position

        self.mapper = vtk.vtkPolyDataMapper()
        self.actor.SetMapper(self.mapper)

        self.property = self.actor.GetProperty()
        self.mapper.SetInputConnection(self.source.GetOutputPort())

        self.fig += self
        self.color_opacity(color, opacity)

        if follow_cam:
            self.actor.SetCamera(self.fig.renderer.GetActiveCamera())
コード例 #10
0
    def add_ring_actor(self, marker):
        ringActor = RingActor(marker, self.pw, lineWidth=self.defaultRingLine)
        vis = ringActor.update()
        self.renderer.AddActor(ringActor)
        self.ringActors[marker.uuid] = ringActor

        text = vtk.vtkVectorText()
        text.SetText(marker.get_label())
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInput(text.GetOutput())

        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        size = 2*marker.get_size()
        textActor.SetScale(size, size, size)
        x,y,z = marker.get_center()
        textActor.SetPosition(x, y, z)
        textActor.SetCamera(self.camera)
        textActor.GetProperty().SetColor(marker.get_label_color())
        if EventHandler().get_labels_on() and vis:
            textActor.VisibilityOn()
        else:
            textActor.VisibilityOff()

        self.textActors[marker.uuid] = textActor
        self.renderer.AddActor(textActor)
コード例 #11
0
def create_actors(x, y, temperature, is_visible):
    if temperature is None:
        return None, None

    cube_source = vtk.vtkCubeSource()
    cube_source.SetXLength(30)
    cube_source.SetYLength(30)
    cube_source.SetZLength(1)
    cube_source.SetCenter(x, y - 19, 0)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(cube_source.GetOutputPort())

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    temperature_label = temperature_labels[get_temperature_label_index(
        temperature)]
    actor.GetProperty().SetColor(
        temperature_colors.GetColor3d(temperature_label))
    actor.SetVisibility(is_visible)

    atext = vtk.vtkVectorText()
    atext.SetText("{:.1f}".format(temperature).center(5))
    textMapper = vtk.vtkPolyDataMapper()
    textMapper.SetInputConnection(atext.GetOutputPort())
    textActor = vtk.vtkFollower()
    textActor.SetMapper(textMapper)
    textActor.SetScale(8, 8, 8)
    textActor.AddPosition(x - 16, y - 23, 1)
    textActor.GetProperty().SetColor(0, 0, 0)
    textActor.SetVisibility(is_visible)

    return actor, textActor
コード例 #12
0
    def add_ring_actor(self, marker):
        ringActor = RingActor(marker, self.pw, lineWidth=self.defaultRingLine)
        vis = ringActor.update()
        self.renderer.AddActor(ringActor)
        self.ringActors.AddItem(ringActor)

        # a hack to keep vtk from casting my class when I put it in
        # the collection.  If I don't register some func, I lose all
        # the derived methods
        self.observer.AddObserver('EndInteractionEvent', ringActor.silly_hack)

        text = vtk.vtkVectorText()
        text.SetText(marker.get_label())
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInput(text.GetOutput())

        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        size = 2 * marker.get_size()
        textActor.SetScale(size, size, size)
        x, y, z = marker.get_center()
        textActor.SetPosition(x, y, z)
        textActor.SetCamera(self.camera)
        textActor.GetProperty().SetColor(marker.get_label_color())
        if EventHandler().get_labels_on() and vis:
            textActor.VisibilityOn()
        else:
            textActor.VisibilityOff()

        self.textActors[marker] = textActor
        self.renderer.AddActor(textActor)
コード例 #13
0
    def add_marker(self, marker):
        if debug:
            print "PlaneWidgetsXYZ.add_marker(): self.renderer.AddActor(marker)"
        self.renderer.AddActor(marker)

        text = vtk.vtkVectorText()
        text.SetText(marker.get_label())
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInput(text.GetOutput())

        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        size = marker.get_size()
        textActor.SetScale(size, size, size)
        x,y,z = marker.get_center()
        textActor.SetPosition(x+size, y+size, z+size)
        textActor.SetCamera(self.camera)
        textActor.GetProperty().SetColor(marker.get_label_color())
        if EventHandler().get_labels_on():
            if debug:
                print "VisibilityOn"
            textActor.VisibilityOn()
        else:
            if debug:
                print "VisibilityOff"
            textActor.VisibilityOff()


        self.textActors[marker] = textActor
        if debug:
            print "PlaneWidgetsXYZ.add_marker(): self.renderer.AddActor(textActor)"
        self.renderer.AddActor(textActor)
コード例 #14
0
def temperature_actor(x, y, temp, col):
    cube_source = vtk.vtkCubeSource()
    cube_source.SetXLength(30)
    cube_source.SetYLength(30)
    cube_source.SetZLength(1)
    cube_source.SetCenter(x, y - 19, 0)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(cube_source.GetOutputPort())

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(col)
    actor.SetVisibility(True)

    atext = vtk.vtkVectorText()
    atext.SetText("{:.0f}".format(temp).center(4))
    textMapper = vtk.vtkPolyDataMapper()
    textMapper.SetInputConnection(atext.GetOutputPort())
    textActor = vtk.vtkFollower()
    textActor.SetMapper(textMapper)
    textActor.SetScale(8, 8, 8)
    textActor.AddPosition(x - 15, y - 23, 1)
    textActor.GetProperty().SetColor(1, 1, 1)
    textActor.SetVisibility(True)

    return actor, textActor
コード例 #15
0
ファイル: structure_vtk.py プロジェクト: akashneo/pymatgen
    def add_picker(self):
        # Create a cell picker.
        picker = vtk.vtkCellPicker()
        # Create a Python function to create the text for the text mapper used
        # to display the results of picking.
        source = vtk.vtkVectorText()
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(source.GetOutputPort())
        follower = vtk.vtkFollower()
        follower.SetMapper(mapper)
        follower.GetProperty().SetColor((0, 0, 0))
        follower.SetScale(0.2)
        self.ren.AddActor(follower)
        follower.SetCamera(self.ren.GetActiveCamera())
        follower.VisibilityOff()

        def annotate_pick(obj, event):
            if picker.GetCellId() < 0:
                follower.VisibilityOff()
            else:
                pick_pos = picker.GetPickPosition()
                mapper = picker.GetMapper()
                if mapper in self.mapper_map:
                    site = self.mapper_map[mapper]
                    output = [site.species_string, "Frac. coords: " +
                                                   " ".join(["{:.4f}".format(c)
                                                             for c in
                                                             site.frac_coords])]
                    source.SetText("\n".join(output))
                    follower.SetPosition(pick_pos)
                    follower.VisibilityOn()
        picker.AddObserver("EndPickEvent", annotate_pick)
        self.picker = picker
        self.iren.SetPicker(picker)
コード例 #16
0
def make_render_window():

    #cone actor
    cone = vtk.vtkConeSource()
    coneMapper = vtk.vtkPolyDataMapper()
    coneMapper.SetInputConnection(cone.GetOutputPort())
    coneActor = vtk.vtkActor()
    coneActor.SetMapper(coneMapper)

    #text actor following camera
    text = vtk.vtkVectorText()
    text.SetText("Origin")
    textMapper = vtk.vtkPolyDataMapper()
    textMapper.SetInputConnection(text.GetOutputPort())
    textActor = vtk.vtkFollower()
    textActor.SetMapper(textMapper)

    ren = vtk.vtkRenderer()
    ren.AddActor(coneActor)
    ren.AddActor(textActor)
    textActor.SetCamera(ren.GetActiveCamera())

    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    return renWin
コード例 #17
0
    def initArea(self):
        # Zoom items
        self.zitems = []
        
        self.cellTypeActors={}
        self.outlineActor = vtk.vtkActor()
        self.outlineDim=[0,0,0]
        
        self.invisibleCellTypes={}
        self.typesInvisibleStr=""
        self.set3DInvisibleTypes()
        
        axesActor = vtk.vtkActor()
        axisTextActor = vtk.vtkFollower()
        
        self.clut = vtk.vtkLookupTable()
        self.clut.SetHueRange(0.67, 0.0)
        self.clut.SetSaturationRange(1.0,1.0)
        self.clut.SetValueRange(1.0,1.0)
        self.clut.SetAlphaRange(1.0,1.0)
        self.clut.SetNumberOfColors(1024)
        self.clut.Build()

        ## Set up the mapper and actor (3D) for concentration field.
        # self.conMapper = vtk.vtkPolyDataMapper()
        self.conActor = vtk.vtkActor()

        self.glyphsActor=vtk.vtkActor()
        # self.glyphsMapper=vtk.vtkPolyDataMapper()
        
        self.cellGlyphsActor  = vtk.vtkActor()
        self.FPPLinksActor  = vtk.vtkActor()

        # Weird attributes
        self.typeActors             = {} # vtkActor
コード例 #18
0
    def mark(x, y, z):
        #function for placing a landmark sphere
        sphere = vtk.vtkSphereSource()
        sphere.SetRadius(1)
        res = 20
        sphere.SetThetaResolution(res)
        sphere.SetPhiResolution(res)
        sphere.SetCenter(x, y, z)
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(sphere.GetOutputPort())

        marker = vtk.vtkActor()
        marker.SetMapper(mapper)
        renderer.AddActor(marker)
        marker.GetProperty().SetColor((1, 0, 0))

        #annotate the mark
        atext = vtk.vtkVectorText()
        atext.SetText(str(len(landmarks) + 1))
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInputConnection(atext.GetOutputPort())
        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        textActor.SetScale(3, 3, 3)
        textActor.AddPosition(x, y, z)
        textActor.SetCamera(renderer.GetActiveCamera())
        actortextdict[marker] = textActor
        renderer.AddActor(textActor)

        show_m.iren.Render()
コード例 #19
0
ファイル: structure_vtk.py プロジェクト: bkappes/pymatgen
    def add_picker(self):
        # Create a cell picker.
        picker = vtk.vtkCellPicker()
        # Create a Python function to create the text for the text mapper used
        # to display the results of picking.
        source = vtk.vtkVectorText()
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(source.GetOutputPort())
        follower = vtk.vtkFollower()
        follower.SetMapper(mapper)
        follower.GetProperty().SetColor((0, 0, 0))
        follower.SetScale(0.2)
        self.ren.AddActor(follower)
        follower.SetCamera(self.ren.GetActiveCamera())
        follower.VisibilityOff()

        def annotate_pick(obj, event):
            if picker.GetCellId() < 0:
                follower.VisibilityOff()
            else:
                pick_pos = picker.GetPickPosition()
                mapper = picker.GetMapper()
                if mapper in self.mapper_map:
                    site = self.mapper_map[mapper]
                    output = [
                        site.species_string, "Frac. coords: " + " ".join(
                            ["{:.4f}".format(c) for c in site.frac_coords])
                    ]
                    source.SetText("\n".join(output))
                    follower.SetPosition(pick_pos)
                    follower.VisibilityOn()

        picker.AddObserver("EndPickEvent", annotate_pick)
        self.picker = picker
        self.iren.SetPicker(picker)
コード例 #20
0
    def add_axes_labels(self):
        labels = shared.labels
        self.axes_labels=labels
        self.axes_labels_actors=[]
        size = abs(self.imageData.GetSpacing()[0]) * 5
        for i,b in enumerate(self.imageData.GetBounds()):
            coords = list(self.imageData.GetCenter())
            coords[i/2] = b*1.12
            idx_label = 1*i #historical reasons for using this
            label = labels[idx_label]
            if shared.debug: print i,b, coords, label
            if self.orientation == 0:
                if label in ["R","L"]:
                    continue
            if self.orientation == 1:
                if label in ["A","P"]:
                    continue
            if self.orientation == 2:
                if label in ["S","I"]:
                    continue

            #Orientation should be correct due to reading affine in vtkNifti
            text = vtk.vtkVectorText()
            text.SetText(label)
            textMapper = vtk.vtkPolyDataMapper()
            textMapper.SetInput(text.GetOutput())
            textActor = vtk.vtkFollower()
            textActor.SetMapper(textMapper)
            textActor.SetScale(size, size, size)
            x,y,z = coords
            textActor.SetPosition(x, y, z)
            textActor.GetProperty().SetColor(*self.axes_labels_color)
            textActor.SetCamera(self.camera)
            self.axes_labels_actors.append(textActor)
            self.renderer.AddActor(textActor)

        #Reorient camera to have head up
        center = self.imageData.GetCenter()
        spacing = self.imageData.GetSpacing()
        bounds = np.array(self.imageData.GetBounds())
        if shared.debug: print "***center,spacing,bounds", center,spacing,bounds
        pos = [center[0], center[1], center[2]]
        camera_up = [0,0,0]
        if self.orientation == 0:
            pos[0] += max((bounds[1::2]-bounds[0::2]))*2
            camera_up[2] = 1 
        elif self.orientation == 1:
            pos[1] += max((bounds[1::2]-bounds[0::2]))*2
            camera_up[2] = 1
        elif self.orientation == 2:
            pos[2] += max((bounds[1::2]-bounds[0::2]))*2
            camera_up[0] = -1
        if shared.debug: print camera_up
        fpu = center, pos, tuple(camera_up)
        if shared.debug: print "***fpu2:", fpu
        self.set_camera(fpu)
        self.scroll_depth(self.sliceIncrement)
コード例 #21
0
ファイル: plot_3d.py プロジェクト: jeonkiwan/PythonTutorial
def plot_embedding_3d(X, Y, title=None):

    renderer = vtk.vtkRenderer()
    renderer.GradientBackgroundOn()
    renderer.SetBackground2(0.05, 0.05, 0.05)
    renderer.SetBackground(0.25, 0.25, 0.31)

    x_min, x_max = np.min(X, 0), np.max(X, 0)
    X = (X - x_min) / (x_max - x_min)

    camera = renderer.GetActiveCamera()

    for i, pos in enumerate(X):
        #         print(i, pos)
        text = vtk.vtkVectorText()
        text.SetText('M' if Y[i] > 0 else 'B')
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(text.GetOutputPort())
        actor = vtk.vtkFollower()
        actor.SetMapper(mapper)
        actor.SetScale(0.02, 0.02, 0.02)
        actor.AddPosition(pos)
        actor.SetCamera(camera)
        if Y[i]:
            actor.GetProperty().SetColor(1.0, 0.8, 0.25)
        else:
            actor.GetProperty().SetColor(0.25, 0.75, 0.9)
        renderer.AddActor(actor)

    renderer.ResetCamera()
    renderer.ResetCameraClippingRange()

    renwin = vtk.vtkRenderWindow()
    renwin.AddRenderer(renderer)
    renwin.SetSize(800, 800)
    renwin.Render()

    iren = vtk.vtkRenderWindowInteractor()
    iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
    iren.SetRenderWindow(renwin)
    iren.Start()

    #     focal = camera.GetFocalPoint()
    #     pos = camera.GetPosition()

    #     camera.SetFocalPoint(focal)
    #     camera.SetPosition(pos)
    # camera.Azimuth(20);
    # camera.Elevation(40);
    # # renderer.SetActiveCamera(camera)
    # camera.Roll(50);

    # renderer.ResetCamera()
    # renderer.ResetCameraClippingRange()

    return renderer
コード例 #22
0
ファイル: Graphics.py プロジェクト: TomRegan/synedoche
 def _draw_text(self):
     for i in range(len(self.text_mappers)):
         actor = vtkFollower()
         actor.SetMapper(self.text_mappers[i])
         actor.GetProperty().SetColor(Colours.BASE02)
         actor.SetScale(2.0, 2.0, 2.0)
         # Tweak to shift the text a little more central
         pos = [x-5.0 for x in self.layout_grid[i]]
         actor.AddPosition(pos)
         self.actors.append(actor)
コード例 #23
0
ファイル: Main.py プロジェクト: cliburn/flow
 def BuildLabelActor(self, text, op_dict):
     label = vtk.vtkVectorText()
     label.SetText(text)
     labelTransform = self.TransformLabel(label, op_dict)
     labelTransformFilter = self.TransformLabelFilter(label, labelTransform)
     labelMapper = vtk.vtkPolyDataMapper()
     labelMapper.SetInput(labelTransformFilter.GetOutput())
     actor = vtk.vtkFollower()
     actor.SetMapper(labelMapper)
     return actor
コード例 #24
0
def polygon(pos=[0, 0, 0],
            normal=[0, 0, 1],
            nsides=6,
            r=1,
            c='coral',
            bc='darkgreen',
            lw=1,
            alpha=1,
            legend=None,
            texture=None,
            followcam=False,
            camera=None):
    '''
    Build a 2D polygon of `nsides` of radius `r` oriented as `normal`.

    If ``followcam=True`` the polygon will always reorient itself to current camera.
    '''
    ps = vtk.vtkRegularPolygonSource()
    ps.SetNumberOfSides(nsides)
    ps.SetRadius(r)
    ps.SetNormal(-np.array(normal))
    ps.Update()

    tf = vtk.vtkTriangleFilter()
    tf.SetInputConnection(ps.GetOutputPort())
    tf.Update()

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(tf.GetOutputPort())
    if followcam:  # follow cam
        actor = vtk.vtkFollower()
        actor.SetCamera(camera)
        if not camera:
            colors.printc('Warning: vtkCamera does not yet exist for polygon',
                          c=5)
    else:
        actor = Actor()  # vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(colors.getColor(c))
    # check if color string contains a float, in this case ignore alpha
    al = colors._getAlpha(c)
    if al:
        alpha = al
    actor.GetProperty().SetOpacity(alpha)
    actor.GetProperty().SetLineWidth(lw)
    actor.GetProperty().SetInterpolationToFlat()
    if bc:  # defines a specific color for the backface
        backProp = vtk.vtkProperty()
        backProp.SetDiffuseColor(colors.getColor(bc))
        backProp.SetOpacity(alpha)
        actor.SetBackfaceProperty(backProp)
    if texture:
        actor.texture(texture)
    actor.SetPosition(pos)
    return actor
コード例 #25
0
ファイル: TextOrigin.py プロジェクト: wangsen53/vtk-examples
def main():
    colors = vtk.vtkNamedColors()

    # Create the axes and the associated mapper and actor.
    axes = vtk.vtkAxes()
    axes.SetOrigin(0, 0, 0)
    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInputConnection(axes.GetOutputPort())
    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)

    # Create the 3D text and the associated mapper and follower (a type of actor).  Position the text so it is displayed over the origin of the axes.
    atext = vtk.vtkVectorText()
    atext.SetText('Origin')
    textMapper = vtk.vtkPolyDataMapper()
    textMapper.SetInputConnection(atext.GetOutputPort())
    textActor = vtk.vtkFollower()
    textActor.SetMapper(textMapper)
    textActor.SetScale(0.2, 0.2, 0.2)
    textActor.AddPosition(0, -0.1, 0)
    textActor.GetProperty().SetColor(colors.GetColor3d('Peacock'))

    # Create the Renderer, RenderWindow, and RenderWindowInteractor.
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindow.SetSize(640, 480)

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

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

    # Add the actors to the renderer.
    renderer.AddActor(axesActor)
    renderer.AddActor(textActor)

    renderer.SetBackground(colors.GetColor3d('Silver'))

    # Zoom in closer.
    renderer.ResetCamera()
    renderer.GetActiveCamera().Zoom(1.6)

    renderer.SetBackground(colors.GetColor3d('Silver'))

    # Reset the clipping range of the camera; set the camera of the follower; render.
    renderer.ResetCameraClippingRange()
    textActor.SetCamera(renderer.GetActiveCamera())

    interactor.Initialize()
    renderWindow.SetWindowName('TextOrigin')
    renderWindow.Render()
    interactor.Start()
コード例 #26
0
ファイル: render.py プロジェクト: GVallicrosa/FabQtV2
def generateAxes(printer):
    xmax, ymax, zmax = printer.getPrintingDimensions()
    axes = vtk.vtkAxes()
    axes.SetOrigin(-xmax/2, -ymax/2, 0)
    axes.SetScaleFactor(20)
    axesTubes = vtk.vtkTubeFilter()
    axesTubes.SetInputConnection(axes.GetOutputPort())
    axesTubes.SetRadius(2)
    axesTubes.SetNumberOfSides(4)
    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInputConnection(axesTubes.GetOutputPort())
    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)
    XText = vtk.vtkVectorText()
    XText.SetText('X')
    XTextMapper = vtk.vtkPolyDataMapper()
    XTextMapper.SetInputConnection(XText.GetOutputPort())
    XActor = vtk.vtkFollower()
    XActor.SetMapper(XTextMapper)
    XActor.SetScale(5, 5, 5)
    XActor.SetPosition(-xmax/2 + 20, -ymax/2 - 10, 5)
    XActor.GetProperty().SetColor(1, 0, 0)
    YText = vtk.vtkVectorText()
    YText.SetText('Y')
    YTextMapper = vtk.vtkPolyDataMapper()
    YTextMapper.SetInputConnection(YText.GetOutputPort())
    YActor = vtk.vtkFollower()
    YActor.SetMapper(YTextMapper)
    YActor.SetScale(5, 5, 5)
    YActor.SetPosition(-xmax/2 - 5, -ymax/2 + 20, 5)
    YActor.GetProperty().SetColor(1, 1, 0)
    ZText = vtk.vtkVectorText()
    ZText.SetText('Z')
    ZTextMapper = vtk.vtkPolyDataMapper()
    ZTextMapper.SetInputConnection(ZText.GetOutputPort())
    ZActor = vtk.vtkFollower()
    ZActor.SetMapper(ZTextMapper)
    ZActor.SetScale(5, 5, 5)
    ZActor.SetPosition(-xmax/2, -ymax/2, 25)
    ZActor.GetProperty().SetColor(0, 1, 0)
    return axesActor, XActor, YActor, ZActor
コード例 #27
0
ファイル: CubeSection.py プロジェクト: agamdua/mystic
def getAxes(Origin, scale=1):
    axes = vtk.vtkAxes()
    axes.SetOrigin(*Origin)
    axes.SetScaleFactor(scale)

    axesTubes = vtk.vtkTubeFilter()

    axesTubes.SetInputConnection(axes.GetOutputPort())
    axesTubes.SetRadius(0.01)
    axesTubes.SetNumberOfSides(6)

    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInputConnection(axesTubes.GetOutputPort())

    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)

    XText = vtk.vtkVectorText()
    XText.SetText("x")

    XTextMapper = vtk.vtkPolyDataMapper()
    XTextMapper.SetInputConnection(XText.GetOutputPort())

    XActor = vtk.vtkFollower()
    XActor.SetMapper(XTextMapper)
    XActor.SetScale(.1, .1, .1)
    XActor.SetPosition(1, Origin[1], Origin[2])
    XActor.GetProperty().SetColor(0, 0, 0)

    YText = vtk.vtkVectorText()
    YText.SetText("y")

    YTextMapper = vtk.vtkPolyDataMapper()
    YTextMapper.SetInputConnection(YText.GetOutputPort())

    YActor = vtk.vtkFollower()
    YActor.SetMapper(YTextMapper)
    YActor.SetScale(.1, .1, .1)
    YActor.SetPosition(Origin[0], 1, Origin[2])
    YActor.GetProperty().SetColor(0, 0, 0)
    return axesActor, XActor, YActor
コード例 #28
0
ファイル: CubeSection.py プロジェクト: Magellen/mystic
def getAxes(Origin, scale = 1):
    axes = vtk.vtkAxes()
    axes.SetOrigin(*Origin)
    axes.SetScaleFactor(scale)

    axesTubes = vtk.vtkTubeFilter()

    axesTubes.SetInputConnection(axes.GetOutputPort())
    axesTubes.SetRadius(0.01)
    axesTubes.SetNumberOfSides(6)

    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInputConnection(axesTubes.GetOutputPort())

    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)

    XText = vtk.vtkVectorText()
    XText.SetText("x")

    XTextMapper = vtk.vtkPolyDataMapper()
    XTextMapper.SetInputConnection(XText.GetOutputPort())

    XActor = vtk.vtkFollower()
    XActor.SetMapper(XTextMapper)
    XActor.SetScale(.1, .1, .1)
    XActor.SetPosition(1, Origin[1], Origin[2])
    XActor.GetProperty().SetColor(0, 0, 0)

    YText = vtk.vtkVectorText()
    YText.SetText("y")

    YTextMapper = vtk.vtkPolyDataMapper()
    YTextMapper.SetInputConnection(YText.GetOutputPort())

    YActor = vtk.vtkFollower()
    YActor.SetMapper(YTextMapper)
    YActor.SetScale(.1, .1, .1)
    YActor.SetPosition(Origin[0], 1, Origin[2])
    YActor.GetProperty().SetColor(0, 0, 0)
    return axesActor, XActor, YActor
コード例 #29
0
ファイル: VTKUtil.py プロジェクト: simpeg/presentations
def makeTextActor(text,size,pos):
    at = vtk.vtkVectorText()
    at.SetText(text)
    tMap = vtk.vtkPolyDataMapper()
    tMap.SetInputConnection(at.GetOutputPort())
    tAct = vtk.vtkFollower()
    tAct.SetMapper(tMap)
    tAct.GetProperty().SetColor(0,0,0)
    tAct.SetScale(size)
    tAct.SetPosition(pos)
    tAct.PickableOff()
    return tAct
コード例 #30
0
ファイル: structure_vtk.py プロジェクト: chenweis/pymatgen
 def add_text(self, coords, text, color = (0,0,0)):
     source = vtk.vtkVectorText()
     source.SetText(text)
     mapper = vtk.vtkPolyDataMapper()
     mapper.SetInputConnection(source.GetOutputPort())
     follower = vtk.vtkFollower()
     follower.SetMapper(mapper)
     follower.GetProperty().SetColor(color)
     follower.SetPosition(coords)
     follower.SetScale(0.5)
     self.ren.AddActor(follower)
     follower.SetCamera(self.ren.GetActiveCamera())
コード例 #31
0
def Polygon(pos=(0, 0, 0),
            normal=(0, 0, 1),
            nsides=6,
            r=1,
            c="coral",
            bc="darkgreen",
            lw=1,
            alpha=1,
            followcam=False):
    """
    Build a 2D polygon of `nsides` of radius `r` oriented as `normal`.

    :param followcam: if `True` the text will auto-orient itself to the active camera.
        A ``vtkCamera`` object can also be passed.
    :type followcam: bool, vtkCamera  
    
    |Polygon|
    """
    ps = vtk.vtkRegularPolygonSource()
    ps.SetNumberOfSides(nsides)
    ps.SetRadius(r)
    ps.SetNormal(-np.array(normal))
    ps.Update()

    tf = vtk.vtkTriangleFilter()
    tf.SetInputConnection(ps.GetOutputPort())
    tf.Update()

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(tf.GetOutputPort())
    if followcam:
        import vtkplotter.plotter as plt

        actor = vtk.vtkFollower()
        if isinstance(followcam, vtk.vtkCamera):
            actor.SetCamera(followcam)
        else:
            actor.SetCamera(plt._plotter_instance.camera)
    else:
        actor = Actor()

    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(colors.getColor(c))
    actor.GetProperty().SetOpacity(alpha)
    actor.GetProperty().SetLineWidth(lw)
    actor.GetProperty().SetInterpolationToFlat()
    if bc:  # defines a specific color for the backface
        backProp = vtk.vtkProperty()
        backProp.SetDiffuseColor(colors.getColor(bc))
        backProp.SetOpacity(alpha)
        actor.SetBackfaceProperty(backProp)
    actor.SetPosition(pos)
    return actor
コード例 #32
0
 def get_axis_label_actor(self, text, position, ren):
     atext = vtk.vtkVectorText()
     atext.SetText(text)
     textMapper = vtk.vtkPolyDataMapper()
     textMapper.SetInputConnection(atext.GetOutputPort())
     textActor = vtk.vtkFollower()
     textActor.SetMapper(textMapper)
     textActor.SetScale(20, 20, 20)
     textActor.AddPosition(position[0], position[1], position[2])
     textActor.GetProperty().SetColor(0, 0, 0)
     textActor.SetCamera(ren.GetActiveCamera())
     return textActor
コード例 #33
0
ファイル: DisplayBlockMesh.py プロジェクト: minhbau/PyFoam
 def addVertex(self,index):
     coord=self.vertices[index]
     self.vActors[index]=self.addPoint(coord)
     text=vtk.vtkVectorText()
     text.SetText(str(index))
     tMapper=vtk.vtkPolyDataMapper()
     tMapper.SetInput(text.GetOutput())
     tActor = vtk.vtkFollower()
     tActor.SetMapper(tMapper)
     tActor.SetScale(2*self.vRadius,2*self.vRadius,2*self.vRadius)
     tActor.AddPosition(coord[0]+self.vRadius,coord[1]+self.vRadius,coord[2]+self.vRadius)
     tActor.SetCamera(self.cam)
     tActor.GetProperty().SetColor(1.0,0.,0.)
     self.ren.AddActor(tActor)
コード例 #34
0
ファイル: ImplicitFitting.py プロジェクト: quentan/Algorithms
def add_text(_renderer, position, text="TEXT", color=[0.5, 0.5, 0.5], scale=0.1):
    # Create text with the x-y-z coordinate system
    _text = vtk.vtkVectorText()
    _text.SetText(text)
    mapper_text = vtk.vtkPolyDataMapper()
    mapper_text.SetInputConnection(_text.GetOutputPort())
    # actor_text_origin = vtk.vtkActor()
    actor_text = vtk.vtkFollower()
    # actor_text.SetCamera(_renderer.GetActiveCamera())
    actor_text.SetMapper(mapper_text)
    actor_text.SetScale(scale, scale, scale)
    actor_text.GetProperty().SetColor(color)
    actor_text.AddPosition([sum(x) for x in zip(position, [0, -0.1, 0])])  # plus of 2 arrays

    _renderer.AddActor(actor_text)
コード例 #35
0
def CreateTextItem(text, scale, camera, color=None):
	textSource = vtkVectorText()
	textSource.SetText(text)

	textMapper = vtkPolyDataMapper()
	textMapper.SetInputConnection(textSource.GetOutputPort())

	textFollower = vtkFollower()
	textFollower.SetMapper(textMapper)
	textFollower.SetCamera(camera)
	textFollower.SetScale(scale)

	# Give the actor a custom color
	ColorActor(textFollower, color)

	return textFollower
コード例 #36
0
def CreateTextItem(text, scale, camera, color=None):
    textSource = vtkVectorText()
    textSource.SetText(text)

    textMapper = vtkPolyDataMapper()
    textMapper.SetInputConnection(textSource.GetOutputPort())

    textFollower = vtkFollower()
    textFollower.SetMapper(textMapper)
    textFollower.SetCamera(camera)
    textFollower.SetScale(scale)

    # Give the actor a custom color
    ColorActor(textFollower, color)

    return textFollower
コード例 #37
0
ファイル: actor.py プロジェクト: sitek/fury
def label(text='Origin',
          pos=(0, 0, 0),
          scale=(0.2, 0.2, 0.2),
          color=(1, 1, 1)):
    """Create a label actor.

    This actor will always face the camera

    Parameters
    ----------
    text : str
        Text for the label.
    pos : (3,) array_like, optional
        Left down position of the label.
    scale : (3,) array_like
        Changes the size of the label.
    color : (3,) array_like
        Label color as ``(r,g,b)`` tuple.

    Returns
    -------
    l : vtkActor object
        Label.

    Examples
    --------
    >>> from fury import window, actor
    >>> scene = window.Scene()
    >>> l = actor.label(text='Hello')
    >>> scene.add(l)
    >>> #window.show(scene)

    """
    atext = vtk.vtkVectorText()
    atext.SetText(text)

    textm = vtk.vtkPolyDataMapper()
    textm.SetInputConnection(atext.GetOutputPort())

    texta = vtk.vtkFollower()
    texta.SetMapper(textm)
    texta.SetScale(scale)

    texta.GetProperty().SetColor(color)
    texta.SetPosition(pos)

    return texta
コード例 #38
0
 def vtk_label_iod(receptor_dirs, triangles, renderers):
     dists = get_mean_interommatidial_distance(receptor_dirs, triangles)
     pi = 3.1415926535897931
     R2D = 180.0 / pi
     for v, dist in zip(receptor_dirs, dists):
         atext = vtk.vtkVectorText()
         atext.SetText("%.1f" % (dist * R2D, ))
         textMapper = vtk.vtkPolyDataMapper()
         textMapper.SetInputConnection(atext.GetOutputPort())
         textActor = vtk.vtkFollower()
         textActor.SetMapper(textMapper)
         scale = 0.03
         textActor.SetScale(scale, scale, scale)
         mult = 1.02
         textActor.AddPosition(v.x * mult, v.y * mult, v.z * mult)
         for renderer in renderers:
             renderer.AddActor(textActor)
コード例 #39
0
 def vtk_label_iod( receptor_dirs, triangles, renderers ):
     dists = get_mean_interommatidial_distance( receptor_dirs, triangles )
     pi = 3.1415926535897931
     R2D = 180.0/pi
     for v,dist in zip(receptor_dirs,dists):
         atext = vtk.vtkVectorText()
         atext.SetText("%.1f"%(dist*R2D,))
         textMapper = vtk.vtkPolyDataMapper()
         textMapper.SetInput(atext.GetOutput())
         textActor = vtk.vtkFollower()
         textActor.SetMapper(textMapper)
         scale = 0.03
         textActor.SetScale(scale, scale, scale)
         mult = 1.02
         textActor.AddPosition(v.x*mult,v.y*mult,v.z*mult)
         for renderer in renderers:
             renderer.AddActor( textActor )
コード例 #40
0
    def add_axes_labels(self):
        #if shared.debug: print "***Adding axes labels"
        #if shared.debug: print labels
        labels = shared.labels
        #labels = list(np.array(labels)[[4,5,2,3,0,1]])
        self.axes_labels=labels
        self.axes_labels_actors=[]
        size = abs(self.imageData.GetSpacing()[0]) * 5
        #if shared.debug: print "***size", size
        for i,b in enumerate(self.imageData.GetBounds()):
            coords = list(self.imageData.GetCenter())
            coords[i/2] = b*1.1
            #Correction for negative spacings
            idx_label = 1*i
            label = labels[idx_label]
            if shared.debug: print i,b, coords, label
            #Orientation should be correct due to reading affine in vtkNifti
            text = vtk.vtkVectorText()
            text.SetText(label)
            textMapper = vtk.vtkPolyDataMapper()
            textMapper.SetInput(text.GetOutput())
            textActor = vtk.vtkFollower()
            textActor.SetMapper(textMapper)
            textActor.SetScale(size, size, size)
            x,y,z = coords
            textActor.SetPosition(x, y, z)
            textActor.GetProperty().SetColor(*self.axes_labels_color)
            textActor.SetCamera(self.camera)
            self.axes_labels_actors.append(textActor)
            self.renderer.AddActor(textActor)

        #Reorient camera to have head up
        center = self.imageData.GetCenter()
        spacing = self.imageData.GetSpacing()
        bounds = np.array(self.imageData.GetBounds())
        if shared.debug: print "***center,spacing,bounds", center,spacing,bounds
        #idx_left = labels.index("L")
        pos = [center[0], center[1], center[2]]
        pos[0] +=  max((bounds[1::2]-bounds[0::2]))*2
        #idx_sup = labels.index("S")
        camera_up = [0,0,0]
        camera_up[2] = 1
        if shared.debug: print camera_up
        fpu = center, pos, tuple(camera_up)
        if shared.debug: print "***fpu2:", fpu
        self.set_camera(fpu)
コード例 #41
0
def drawText(featurePoints, featureText):
    textActorList = []

    #print(len(featureText))
    #print(featurePoints)
    #print(len(featurePoints))
    for i in range(len(featurePoints)):
        atext = vtk.vtkVectorText()
        atext.SetText(featureText[i])
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInputConnection(atext.GetOutputPort())

        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        textActor.SetScale(0.05, 0.05, 0.05)
        textActor.AddPosition(featurePoints[i])
        textActorList.append(textActor)
    return textActorList
コード例 #42
0
ファイル: diffusion.py プロジェクト: Garyfallidis/trn
def addlabel(ren,text='Origin',pos=(0,0,0),scale=(0.1,0.1,0.1)):
    
    atext=vtk.vtkVectorText()
    atext.SetText(text)
    
    textm=vtk.vtkPolyDataMapper()
    textm.SetInput(atext.GetOutput())
    
    texta=vtk.vtkFollower()
    texta.SetMapper(textm)
    texta.SetScale(scale)    
    texta.SetPosition(pos)
    
    ren.AddActor(texta)
    
    texta.SetCamera(ren.GetActiveCamera())
    
    return texta
コード例 #43
0
ファイル: scene.py プロジェクト: pradal/phenomenal
    def get_actor_from_text(text,
                            position=(0, 0, 0),
                            scale=5,
                            color=(0, 0, 1)):

        text_source = vtk.vtkVectorText()
        text_source.SetText(text)
        text_source.Update()

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(text_source.GetOutputPort())

        actor = vtk.vtkFollower()
        actor.SetMapper(mapper)
        actor.SetScale(scale, scale, scale)
        actor.AddPosition(position[0], position[1], position[2])
        actor.GetProperty().SetColor(color[0], color[1], color[2])

        return actor
コード例 #44
0
ファイル: Visualization.py プロジェクト: zahraaa-zu/PyNite
    def __init__(self, member, nodes, textHeight=5):

        # Generate a line for the member
        line = vtk.vtkLineSource()

        # Step through each node in the model and find the position of the i-node and j-node
        for node in nodes:

            # Check to see if the current node is the i-node
            if node.Name == member.iNode.Name:
                Xi = node.X
                Yi = node.Y
                Zi = node.Z
                line.SetPoint1(Xi, Yi, Zi)

            # Check to see if the current node is the j-node
            elif node.Name == member.jNode.Name:
                Xj = node.X
                Yj = node.Y
                Zj = node.Z
                line.SetPoint2(Xj, Yj, Zj)

        # Set up a mapper for the member
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(line.GetOutputPort())

        # Set up an actor for the member
        self.actor = vtk.vtkActor()
        self.actor.SetMapper(mapper)

        # Create the text for the member label
        label = vtk.vtkVectorText()
        label.SetText(member.Name)

        # Set up a mapper for the member label
        lblMapper = vtk.vtkPolyDataMapper()
        lblMapper.SetInputConnection(label.GetOutputPort())

        # Set up an actor for the member label
        self.lblActor = vtk.vtkFollower()
        self.lblActor.SetMapper(lblMapper)
        self.lblActor.SetScale(textHeight, textHeight, textHeight)
        self.lblActor.SetPosition((Xi + Xj) / 2, (Yi + Yj) / 2, (Zi + Zj) / 2)
コード例 #45
0
    def label(text='Origin',
              pos=(0, 0, 0),
              scale=(0.2, 0.2, 0.2),
              color=(1, 1, 1)):

        atext = vtk.vtkVectorText()
        atext.SetText(text)

        textm = vtk.vtkPolyDataMapper()
        textm.SetInputConnection(atext.GetOutputPort())

        texta = vtk.vtkFollower()
        texta.SetMapper(textm)
        texta.SetScale(scale)

        texta.GetProperty().SetColor(color)
        texta.SetPosition(pos)

        return texta
コード例 #46
0
    def mark(x, y, z):
        sphere = vtk.vtkSphereSource()
        sphere.SetRadius(1)
        res = 20
        sphere.SetThetaResolution(res)
        sphere.SetPhiResolution(res)
        sphere.SetCenter(x, y, z)
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(sphere.GetOutputPort())

        marker = vtk.vtkActor()
        marker.SetMapper(mapper)
        renderer.AddActor(marker)
        marker.GetProperty().SetColor((0, 0, 1))

        #annotate the mark
        atext = vtk.vtkVectorText()
        atext.SetText(str(len(landmarks) + 1))
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInputConnection(atext.GetOutputPort())
        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        textActor.SetScale(3, 3, 3)
        textActor.AddPosition(x, y, z)
        textActor.SetCamera(renderer.GetActiveCamera())
        actortextdict[marker] = textActor
        renderer.AddActor(textActor)

        #add line
        if len(landmarks) > 0:
            lineSource = vtk.vtkLineSource()
            lineSource.SetPoint1(landmarks[-1])
            lineSource.SetPoint2([x, y, z])
            mapper = vtk.vtkPolyDataMapper()
            mapper.SetInputConnection(lineSource.GetOutputPort())
            lineActor = vtk.vtkActor()
            lineActor.SetMapper(mapper)
            lineActor.GetProperty().SetLineWidth(4)
            lineActor.GetProperty().SetColor((0, 1, 0))
            actorlinedict[marker] = lineActor
            renderer.AddActor(lineActor)

        show_m.iren.Render()
コード例 #47
0
ファイル: fos.py プロジェクト: fos/fos-pyglet
def label(ren,text='Origin',pos=(0,0,0),scale=(0.2,0.2,0.2),color=(1,1,1)):
    
    ''' Create a label actor 
    This actor will always face the camera
    
    Parameters
    ----------
    ren : vtkRenderer() object as returned from ren()
    text : a text for the label
    pos : left down position of the label
    scale : change the size of the label 
    color : (r,g,b) and RGB tuple
    
    Returns
    ----------
    vtkActor object
    
    Examples
    --------  
    >>> from dipy.viz import fos  
    >>> r=fos.ren()    
    >>> l=fos.label(r)
    >>> fos.add(r,l)
    >>> fos.show(r)
    '''
    atext=vtk.vtkVectorText()
    atext.SetText(text)
    
    textm=vtk.vtkPolyDataMapper()
    textm.SetInput(atext.GetOutput())
    
    texta=vtk.vtkFollower()
    texta.SetMapper(textm)
    texta.SetScale(scale)    

    texta.GetProperty().SetColor(color)
    texta.SetPosition(pos)
    
    ren.AddActor(texta)
    texta.SetCamera(ren.GetActiveCamera())
        
    return texta
コード例 #48
0
ファイル: structure_vtk.py プロジェクト: CompRhys/pymatgen
    def add_text(self, coords, text, color=(0, 0, 0)):
        """
        Add text at a coordinate.

        Args:
            coords: Coordinates to add text at.
            text: Text to place.
            color: Color for text as RGB. Defaults to black.
        """
        source = vtk.vtkVectorText()
        source.SetText(text)
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(source.GetOutputPort())
        follower = vtk.vtkFollower()
        follower.SetMapper(mapper)
        follower.GetProperty().SetColor(color)
        follower.SetPosition(coords)
        follower.SetScale(0.5)
        self.ren.AddActor(follower)
        follower.SetCamera(self.ren.GetActiveCamera())
コード例 #49
0
ファイル: structure_vtk.py プロジェクト: AtlasL/pymatgen
    def add_text(self, coords, text, color=(0, 0, 0)):
        """
        Add text at a coordinate.

        Args:
            coords: Coordinates to add text at.
            text: Text to place.
            color: Color for text as RGB. Defaults to black.
        """
        source = vtk.vtkVectorText()
        source.SetText(text)
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(source.GetOutputPort())
        follower = vtk.vtkFollower()
        follower.SetMapper(mapper)
        follower.GetProperty().SetColor(color)
        follower.SetPosition(coords)
        follower.SetScale(0.5)
        self.ren.AddActor(follower)
        follower.SetCamera(self.ren.GetActiveCamera())
コード例 #50
0
    def __init__(self, render, label, color):
        self.render = render

        self.colors = {
               'Marine Blue': [0.1, 0.2, 0.4],
               'Deep Blue':   [0.2, 0.2, 1.0],
               'Red':         [1.0, 0.0, 0.0],
               'Yellow':      [1.0, 1.0, 0.0],
               'Green':       [0.0, 1.0, 0.0],
               'Orange':      [1.0, 0.5, 0.0],
               'Magenta':     [1.0, 0.0, 1.0],
               'Grey':        [0.5, 0.5, 0.5],
               'Black':       [0.0, 0.0, 0.0],
               'Cyan':        [0.0, 1.0, 1.0],
               'Turquoise':   [0.0, 0.5, 0.5],
               'White':       [1.0, 1.0, 1.0],
               'Light green': [0.5, 1.0, 0.5],
                }

        if color:
            self.color = color
        else:
            self.color = "Yellow"

        self.__isSelected = False

        self.points = vtk.vtkPoints()
        self.points.SetDataTypeToFloat()

        self.property = vtk.vtkProperty()
        self.actor = vtk.vtkActor()
        self.actor.SetProperty(self.property)

        self.label = label
        self.labels = vtk.vtkVectorText()
        self.labels.SetText(label)
        self.labelProp = vtk.vtkProperty()
        self.labelActor = vtk.vtkFollower()
コード例 #51
0
    def testFinancialField(self):

        """
            Demonstrate the use and manipulation of fields and use of
            vtkProgrammableDataObjectSource. This creates fields the hard way
            (as compared to reading a vtk field file), but shows you how to
            interface to your own raw data.

            The image should be the same as financialField.tcl
        """

        xAxis = "INTEREST_RATE"
        yAxis = "MONTHLY_PAYMENT"
        zAxis = "MONTHLY_INCOME"
        scalar = "TIME_LATE"

        # Parse an ascii file and manually create a field. Then construct a
        # dataset from the field.
        dos = vtk.vtkProgrammableDataObjectSource()

        def parseFile():
            f = open(VTK_DATA_ROOT + "/Data/financial.txt", "r")

            line = f.readline().split()
            # From the size calculate the number of lines.
            numPts = int(line[1])
            numLines = (numPts - 1) / 8 + 1

            # create the data object
            field = vtk.vtkFieldData()
            field.AllocateArrays(4)

            # read TIME_LATE - dependent variable
            while True:
                line = f.readline().split()
                if len(line) > 0:
                    break;
            timeLate = vtk.vtkFloatArray()
            timeLate.SetName(line[0])
            for i in range(0, numLines):
                line = f.readline().split()
                for j in line:
                    timeLate.InsertNextValue(float(j))
            field.AddArray(timeLate)

            # MONTHLY_PAYMENT - independent variable
            while True:
                line = f.readline().split()
                if len(line) > 0:
                    break;
            monthlyPayment = vtk.vtkFloatArray()
            monthlyPayment.SetName(line[0])
            for i in range(0, numLines):
                line = f.readline().split()
                for j in line:
                    monthlyPayment.InsertNextValue(float(j))
            field.AddArray(monthlyPayment)

            # UNPAID_PRINCIPLE - skip
            while True:
                line = f.readline().split()
                if len(line) > 0:
                    break;
            for i in range(0, numLines):
                line = f.readline()

            # LOAN_AMOUNT - skip
            while True:
                line = f.readline().split()
                if len(line) > 0:
                    break;
            for i in range(0, numLines):
                line = f.readline()

            # INTEREST_RATE - independent variable
            while True:
                line = f.readline().split()
                if len(line) > 0:
                    break;
            interestRate = vtk.vtkFloatArray()
            interestRate.SetName(line[0])
            for i in range(0, numLines):
                line = f.readline().split()
                for j in line:
                    interestRate.InsertNextValue(float(j))
            field.AddArray(interestRate)

            # MONTHLY_INCOME - independent variable
            while True:
                line = f.readline().split()
                if len(line) > 0:
                    break;
            monthlyIncome = vtk.vtkFloatArray()
            monthlyIncome.SetName(line[0])
            for i in range(0, numLines):
                line = f.readline().split()
                for j in line:
                    monthlyIncome.InsertNextValue(float(j))
            field.AddArray(monthlyIncome)

            dos.GetOutput().SetFieldData(field)

        dos.SetExecuteMethod(parseFile)


        # Create the dataset
        do2ds = vtk.vtkDataObjectToDataSetFilter()
        do2ds.SetInputConnection(dos.GetOutputPort())
        do2ds.SetDataSetTypeToPolyData()
        #format: component#, arrayname, arraycomp, minArrayId, maxArrayId, normalize
        do2ds.DefaultNormalizeOn()
        do2ds.SetPointComponent(0, xAxis, 0)
        do2ds.SetPointComponent(1, yAxis, 0)
        do2ds.SetPointComponent(2, zAxis, 0)
        do2ds.Update()

        rf = vtk.vtkRearrangeFields()
        rf.SetInputConnection(do2ds.GetOutputPort())
        rf.AddOperation("MOVE", scalar, "DATA_OBJECT", "POINT_DATA")
        rf.RemoveOperation("MOVE", scalar, "DATA_OBJECT", "POINT_DATA")
        rf.AddOperation("MOVE", scalar, "DATA_OBJECT", "POINT_DATA")
        rf.RemoveAllOperations()
        rf.AddOperation("MOVE", scalar, "DATA_OBJECT", "POINT_DATA")
        rf.Update()
        max = rf.GetOutput().GetPointData().GetArray(scalar).GetRange(0)[1]


        calc = vtk.vtkArrayCalculator()
        calc.SetInputConnection(rf.GetOutputPort())
        calc.SetAttributeModeToUsePointData()
        calc.SetFunction("s / %f" % max)
        calc.AddScalarVariable("s", scalar, 0)
        calc.SetResultArrayName("resArray")

        aa = vtk.vtkAssignAttribute()
        aa.SetInputConnection(calc.GetOutputPort())
        aa.Assign("resArray", "SCALARS", "POINT_DATA")
        aa.Update()

        rf2 = vtk.vtkRearrangeFields()
        rf2.SetInputConnection(aa.GetOutputPort())
        rf2.AddOperation("COPY", "SCALARS", "POINT_DATA", "DATA_OBJECT")

        # construct pipeline for original population
        popSplatter = vtk.vtkGaussianSplatter()
        popSplatter.SetInputConnection(rf2.GetOutputPort())
        popSplatter.SetSampleDimensions(50, 50, 50)
        popSplatter.SetRadius(0.05)
        popSplatter.ScalarWarpingOff()
        popSurface = vtk.vtkContourFilter()
        popSurface.SetInputConnection(popSplatter.GetOutputPort())
        popSurface.SetValue(0, 0.01)
        popMapper = vtk.vtkPolyDataMapper()
        popMapper.SetInputConnection(popSurface.GetOutputPort())
        popMapper.ScalarVisibilityOff()
        popMapper.ImmediateModeRenderingOn()
        popActor = vtk.vtkActor()
        popActor.SetMapper(popMapper)
        popActor.GetProperty().SetOpacity(0.3)
        popActor.GetProperty().SetColor(.9, .9, .9)

        # construct pipeline for delinquent population
        lateSplatter = vtk.vtkGaussianSplatter()
        lateSplatter.SetInputConnection(aa.GetOutputPort())
        lateSplatter.SetSampleDimensions(50, 50, 50)
        lateSplatter.SetRadius(0.05)
        lateSplatter.SetScaleFactor(0.05)
        lateSurface = vtk.vtkContourFilter()
        lateSurface.SetInputConnection(lateSplatter.GetOutputPort())
        lateSurface.SetValue(0, 0.01)
        lateMapper = vtk.vtkPolyDataMapper()
        lateMapper.SetInputConnection(lateSurface.GetOutputPort())
        lateMapper.ScalarVisibilityOff()
        lateActor = vtk.vtkActor()
        lateActor.SetMapper(lateMapper)
        lateActor.GetProperty().SetColor(1.0, 0.0, 0.0)

        # create axes
        popSplatter.Update()
        bounds = popSplatter.GetOutput().GetBounds()
        axes = vtk.vtkAxes()
        axes.SetOrigin(bounds[0], bounds[2], bounds[4])
        axes.SetScaleFactor(popSplatter.GetOutput().GetLength() / 5.0)
        axesTubes = vtk.vtkTubeFilter()
        axesTubes.SetInputConnection(axes.GetOutputPort())
        axesTubes.SetRadius(axes.GetScaleFactor() / 25.0)
        axesTubes.SetNumberOfSides(6)
        axesMapper = vtk.vtkPolyDataMapper()
        axesMapper.SetInputConnection(axesTubes.GetOutputPort())
        axesActor = vtk.vtkActor()
        axesActor.SetMapper(axesMapper)

        # label the axes
        XText = vtk.vtkVectorText()
        XText.SetText(xAxis)
        XTextMapper = vtk.vtkPolyDataMapper()
        XTextMapper.SetInputConnection(XText.GetOutputPort())
        XActor = vtk.vtkFollower()
        XActor.SetMapper(XTextMapper)
        XActor.SetScale(0.02, .02, .02)
        XActor.SetPosition(0.35, -0.05, -0.05)
        XActor.GetProperty().SetColor(0, 0, 0)

        YText = vtk.vtkVectorText()
        YText.SetText(yAxis)
        YTextMapper = vtk.vtkPolyDataMapper()
        YTextMapper.SetInputConnection(YText.GetOutputPort())
        YActor = vtk.vtkFollower()
        YActor.SetMapper(YTextMapper)
        YActor.SetScale(0.02, .02, .02)
        YActor.SetPosition(-0.05, 0.35, -0.05)
        YActor.GetProperty().SetColor(0, 0, 0)

        ZText = vtk.vtkVectorText()
        ZText.SetText(zAxis)
        ZTextMapper = vtk.vtkPolyDataMapper()
        ZTextMapper.SetInputConnection(ZText.GetOutputPort())
        ZActor = vtk.vtkFollower()
        ZActor.SetMapper(ZTextMapper)
        ZActor.SetScale(0.02, .02, .02)
        ZActor.SetPosition(-0.05, -0.05, 0.35)
        ZActor.GetProperty().SetColor(0, 0, 0)

        # Graphics stuff
        #
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)
        renWin.SetWindowName("vtk(-, Field.Data")
        renWin.SetSize(300, 300)

        # Add the actors to the renderer, set the background and size
        #
        ren.AddActor(axesActor)
        ren.AddActor(lateActor)
        ren.AddActor(XActor)
        ren.AddActor(YActor)
        ren.AddActor(ZActor)
        ren.AddActor(popActor) #it's last because its translucent)
        ren.SetBackground(1, 1, 1)

        camera = vtk.vtkCamera()
        camera.SetClippingRange(.274, 13.72)
        camera.SetFocalPoint(0.433816, 0.333131, 0.449)
        camera.SetPosition(-1.96987, 1.15145, 1.49053)
        camera.SetViewUp(0.378927, 0.911821, 0.158107)
        ren.SetActiveCamera(camera)
        XActor.SetCamera(camera)
        YActor.SetCamera(camera)
        ZActor.SetCamera(camera)

        # render and interact with data

        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renWin);
        renWin.Render()

        img_file = "financialField3.png"
        vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)
        vtk.test.Testing.interact()
コード例 #52
0
ファイル: financialField.py プロジェクト: kalmchocobo/VTK
    def testFinancialField(self):

        size = 3187 #maximum number possible

        #set size 100 #maximum number possible
        xAxis = "INTEREST_RATE"
        yAxis = "MONTHLY_PAYMENT"
        zAxis = "MONTHLY_INCOME"
        scalar = "TIME_LATE"


        # extract data from field as a polydata (just points), then extract scalars
        fdr = vtk.vtkDataObjectReader()
        fdr.SetFileName(VTK_DATA_ROOT + "/Data/financial.vtk")
        do2ds = vtk.vtkDataObjectToDataSetFilter()
        do2ds.SetInputConnection(fdr.GetOutputPort())
        do2ds.SetDataSetTypeToPolyData()
        #format: component#, arrayname, arraycomp, minArrayId, maxArrayId, normalize
        do2ds.DefaultNormalizeOn()
        do2ds.SetPointComponent(0, xAxis, 0)
        do2ds.SetPointComponent(1, yAxis, 0, 0, size, 1)
        do2ds.SetPointComponent(2, zAxis, 0)
        do2ds.Update()
        fd2ad = vtk.vtkFieldDataToAttributeDataFilter()
        fd2ad.SetInputConnection(do2ds.GetOutputPort())
        fd2ad.SetInputFieldToDataObjectField()
        fd2ad.SetOutputAttributeDataToPointData()
        fd2ad.DefaultNormalizeOn()
        fd2ad.SetScalarComponent(0, scalar, 0)

        # construct pipeline for original population
        popSplatter = vtk.vtkGaussianSplatter()
        popSplatter.SetInputConnection(fd2ad.GetOutputPort())
        popSplatter.SetSampleDimensions(50, 50, 50)
        popSplatter.SetRadius(0.05)
        popSplatter.ScalarWarpingOff()
        popSurface = vtk.vtkMarchingContourFilter()
        popSurface.SetInputConnection(popSplatter.GetOutputPort())
        popSurface.SetValue(0, 0.01)
        popMapper = vtk.vtkPolyDataMapper()
        popMapper.SetInputConnection(popSurface.GetOutputPort())
        popMapper.ScalarVisibilityOff()
        popActor = vtk.vtkActor()
        popActor.SetMapper(popMapper)
        popActor.GetProperty().SetOpacity(0.3)
        popActor.GetProperty().SetColor(.9, .9, .9)

        # construct pipeline for delinquent population
        lateSplatter = vtk.vtkGaussianSplatter()
        lateSplatter.SetInputConnection(fd2ad.GetOutputPort())
        lateSplatter.SetSampleDimensions(50, 50, 50)
        lateSplatter.SetRadius(0.05)
        lateSplatter.SetScaleFactor(0.05)
        lateSurface = vtk.vtkMarchingContourFilter()
        lateSurface.SetInputConnection(lateSplatter.GetOutputPort())
        lateSurface.SetValue(0, 0.01)
        lateMapper = vtk.vtkPolyDataMapper()
        lateMapper.SetInputConnection(lateSurface.GetOutputPort())
        lateMapper.ScalarVisibilityOff()
        lateActor = vtk.vtkActor()
        lateActor.SetMapper(lateMapper)
        lateActor.GetProperty().SetColor(1.0, 0.0, 0.0)

        # create axes
        popSplatter.Update()
        bounds = popSplatter.GetOutput().GetBounds()
        axes = vtk.vtkAxes()
        axes.SetOrigin(bounds[0], bounds[2], bounds[4])
        axes.SetScaleFactor(popSplatter.GetOutput().GetLength() / 5.0)
        axesTubes = vtk.vtkTubeFilter()
        axesTubes.SetInputConnection(axes.GetOutputPort())
        axesTubes.SetRadius(axes.GetScaleFactor() / 25.0)
        axesTubes.SetNumberOfSides(6)
        axesMapper = vtk.vtkPolyDataMapper()
        axesMapper.SetInputConnection(axesTubes.GetOutputPort())
        axesActor = vtk.vtkActor()
        axesActor.SetMapper(axesMapper)

        # label the axes
        XText = vtk.vtkVectorText()
        XText.SetText(xAxis)
        XTextMapper = vtk.vtkPolyDataMapper()
        XTextMapper.SetInputConnection(XText.GetOutputPort())
        XActor = vtk.vtkFollower()
        XActor.SetMapper(XTextMapper)
        XActor.SetScale(0.02, .02, .02)
        XActor.SetPosition(0.35, -0.05, -0.05)
        XActor.GetProperty().SetColor(0, 0, 0)

        YText = vtk.vtkVectorText()
        YText.SetText(yAxis)
        YTextMapper = vtk.vtkPolyDataMapper()
        YTextMapper.SetInputConnection(YText.GetOutputPort())
        YActor = vtk.vtkFollower()
        YActor.SetMapper(YTextMapper)
        YActor.SetScale(0.02, .02, .02)
        YActor.SetPosition(-0.05, 0.35, -0.05)
        YActor.GetProperty().SetColor(0, 0, 0)

        ZText = vtk.vtkVectorText()
        ZText.SetText(zAxis)
        ZTextMapper = vtk.vtkPolyDataMapper()
        ZTextMapper.SetInputConnection(ZText.GetOutputPort())
        ZActor = vtk.vtkFollower()
        ZActor.SetMapper(ZTextMapper)
        ZActor.SetScale(0.02, .02, .02)
        ZActor.SetPosition(-0.05, -0.05, 0.35)
        ZActor.GetProperty().SetColor(0, 0, 0)

        # Graphics stuff
        #
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)
        renWin.SetWindowName("vtk - Field.Data")

        # Add the actors to the renderer, set the background and size
        #
        ren.AddActor(axesActor)
        ren.AddActor(lateActor)
        ren.AddActor(XActor)
        ren.AddActor(YActor)
        ren.AddActor(ZActor)
        ren.AddActor(popActor) #it's last because its translucent)
        ren.SetBackground(1, 1, 1)
        renWin.SetSize(400, 400)

        camera = vtk.vtkCamera()
        camera.SetClippingRange(.274, 13.72)
        camera.SetFocalPoint(0.433816, 0.333131, 0.449)
        camera.SetPosition(-1.96987, 1.15145, 1.49053)
        camera.SetViewUp(0.378927, 0.911821, 0.158107)
        ren.SetActiveCamera(camera)
        XActor.SetCamera(camera)
        YActor.SetCamera(camera)
        ZActor.SetCamera(camera)


        # render and interact with data

        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renWin);
        renWin.Render()

        img_file = "financialField.png"
        vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)
        vtk.test.Testing.interact()
コード例 #53
0
ファイル: sse.py プロジェクト: JDonner/gabbleduck
def show_axes(ren):
    # Create the axes and the associated mapper and actor.
    axes = vtk.vtkAxes()
    axes.SetOrigin(0, 0, 0)
    # length - hardwired for our images, which are usually 80 on a side
    # (80/2 = 40)
    AxisLength = 35.0
    TextScale = 1.5
    TextR = 0.4
    TextG = 0.4
    TextB = 0.8

    axes.SetScaleFactor(AxisLength)

    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInputConnection(axes.GetOutputPort())
    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)

    # Label the axes
    XText = vtk.vtkVectorText()
    XText.SetText("X")

    XTextMapper = vtk.vtkPolyDataMapper()
    XTextMapper.SetInputConnection(XText.GetOutputPort())

    XActor = vtk.vtkFollower()
    XActor.SetMapper(XTextMapper)
    XActor.SetScale(TextScale, TextScale, TextScale)
    XActor.SetPosition(AxisLength, 0.0, 0.0)
    XActor.GetProperty().SetColor(TextR, TextG, TextB)

    YText = vtk.vtkVectorText()
    YText.SetText("Y")

    YTextMapper = vtk.vtkPolyDataMapper()
    YTextMapper.SetInputConnection(YText.GetOutputPort())

    YActor = vtk.vtkFollower()
    YActor.SetMapper(YTextMapper)
    YActor.SetScale(TextScale, TextScale, TextScale)
    YActor.SetPosition(0.0, AxisLength, 0.0)
    YActor.GetProperty().SetColor(TextR, TextG, TextB)

    ZText = vtk.vtkVectorText()
    ZText.SetText("Z")

    ZTextMapper = vtk.vtkPolyDataMapper()
    ZTextMapper.SetInputConnection(ZText.GetOutputPort())

    ZActor = vtk.vtkFollower()
    ZActor.SetMapper(ZTextMapper)
    ZActor.SetScale(TextScale, TextScale, TextScale)
    ZActor.SetPosition(0.0, 0.0, AxisLength)
    ZActor.GetProperty().SetColor(TextR, TextG, TextB)


    ren.AddActor(axesActor)
    ren.AddActor(XActor)
    ren.AddActor(YActor)
    ren.AddActor(ZActor)
コード例 #54
0
    def vtkCube(self, data_matrix=None):

        # We begin by creating the data we want to render.
        # For this tutorial, we create a 3D-image containing three overlaping cubes.
        # This data can of course easily be replaced by data from a medical CT-scan or anything else three dimensional.
        # The only limit is that the data must be reduced to unsigned 8 bit or 16 bit integers.
        #data_matrix = zeros([75, 75, 75], dtype=uint8)
        #data_matrix[0:35, 0:35, 0:35] = 50
        #data_matrix[25:55, 25:55, 25:55] = 100
        #data_matrix[45:74, 45:74, 45:74] = 150

        # For VTK to be able to use the data, it must be stored as a VTK-image. This can be done by the vtkImageImport-class which
        # imports raw data and stores it.
        dataImporter = vtk.vtkImageImport()
        # The preaviusly created array is converted to a string of chars and imported.
        data_string = data_matrix.tostring()
        dataImporter.CopyImportVoidPointer(data_string, len(data_string))
        # The type of the newly imported data is set to unsigned char (uint8)
        dataImporter.SetDataScalarTypeToUnsignedChar()
        # Because the data that is imported only contains an intensity value (it isnt RGB-coded or someting similar), the importer
        # must be told this is the case.
        dataImporter.SetNumberOfScalarComponents(1)
        # The following two functions describe how the data is stored and the dimensions of the array it is stored in. For this
        # simple case, all axes are of length 75 and begins with the first element. For other data, this is probably not the case.
        # I have to admit however, that I honestly dont know the difference between SetDataExtent() and SetWholeExtent() although
        # VTK complains if not both are used.
        dataImporter.SetDataExtent(0, 9, 0, 9, 0, 9)
        dataImporter.SetWholeExtent(0, 9, 0, 9, 0, 9)
        #dataImporter.SetDataExtent(0, 74, 0, 74, 0, 74)
        #dataImporter.SetWholeExtent(0, 74, 0, 74, 0, 74)

        # The following class is used to store transparencyv-values for later retrival. In our case, we want the value 0 to be
        # completly opaque whereas the three different cubes are given different transperancy-values to show how it works.
        alphaChannelFunc = vtk.vtkPiecewiseFunction()
        alphaChannelFunc.AddPoint(0, 0.6)
        alphaChannelFunc.AddPoint(33, 0.2)
        alphaChannelFunc.AddPoint(66, 0.1)
        alphaChannelFunc.AddPoint(100, 0.01)

        # Gradient opacity
        # other way: misfit 0 is anti opacity
        volumeGradientOpacity = vtk.vtkPiecewiseFunction()
        volumeGradientOpacity.AddPoint(70,   1.0)
        volumeGradientOpacity.AddPoint(50,  0.5)
        volumeGradientOpacity.AddPoint(20, 0.0)

        # This class stores color data and can create color tables from a few color points. For this demo, we want the three cubes
        # to be of the colors red green and blue.
        colorFunc = vtk.vtkColorTransferFunction()
        colorFunc.AddRGBPoint(00, 1.0, 0.0, 0.0)
        colorFunc.AddRGBPoint(30, 0.0, 1.0, 0.0)
        colorFunc.AddRGBPoint(60, 0.0, 0.0, 1.0)

        # The preavius two classes stored properties. Because we want to apply these properties to the volume we want to render,
        # we have to store them in a class that stores volume prpoperties.
        volumeProperty = vtk.vtkVolumeProperty()
        volumeProperty.SetColor(colorFunc)
        volumeProperty.SetScalarOpacity(alphaChannelFunc)
        volumeProperty.SetGradientOpacity(volumeGradientOpacity)
        volumeProperty.SetInterpolationTypeToLinear()
        volumeProperty.ShadeOff()
        volumeProperty.SetAmbient(0.1)
        volumeProperty.SetDiffuse(0.6)
        volumeProperty.SetSpecular(0.2)

        # This class describes how the volume is rendered (through ray tracing).
        compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()
        # We can finally create our volume. We also have to specify the data for it, as well as how the data will be rendered.
        volumeMapper = vtk.vtkVolumeRayCastMapper()
        volumeMapper.SetVolumeRayCastFunction(compositeFunction)
        volumeMapper.SetInputConnection(dataImporter.GetOutputPort())

        # The class vtkVolume is used to pair the preaviusly declared volume as well as the properties to be used when rendering that volume.
        volume = vtk.vtkVolume()
        volume.SetMapper(volumeMapper)
        volume.SetProperty(volumeProperty)

        # Text am Nullpunkt
        atext = vtk.vtkVectorText()
        atext.SetText("(0,0,0)")
        textMapper = vtk.vtkPolyDataMapper()
        textMapper.SetInputConnection(atext.GetOutputPort())
        textActor = vtk.vtkFollower()
        textActor.SetMapper(textMapper)
        textActor.SetScale(10, 10, 10)
        textActor.AddPosition(0, -0.1, 78)

        # Cube to give some orientation 
        # (from http://www.vtk.org/Wiki/VTK/Examples/Python/Widgets/OrientationMarkerWidget)

        axesActor = vtk.vtkAnnotatedCubeActor();
        axesActor.SetXPlusFaceText('N')
        axesActor.SetXMinusFaceText('S')
        axesActor.SetYMinusFaceText('W')
        axesActor.SetYPlusFaceText('E')
        axesActor.SetZMinusFaceText('D')
        axesActor.SetZPlusFaceText('U')
        axesActor.GetTextEdgesProperty().SetColor(1,1,0)
        axesActor.GetTextEdgesProperty().SetLineWidth(2)
        axesActor.GetCubeProperty().SetColor(0,0,1)

        # With almost everything else ready, its time to initialize the renderer and window, as well as creating a method for exiting the application
        renderer = vtk.vtkRenderer()
        renderWin = vtk.vtkRenderWindow()
        renderWin.AddRenderer(renderer)
        renderInteractor = vtk.vtkRenderWindowInteractor()
        renderInteractor.SetRenderWindow(renderWin)

        axes = vtk.vtkOrientationMarkerWidget()
        axes.SetOrientationMarker(axesActor)
        axes.SetInteractor(renderInteractor)
        axes.EnabledOn()
        axes.InteractiveOn()
        renderer.ResetCamera()

        # We add the volume to the renderer ...
        renderer.AddVolume(volume)
        # ... set background color to white ...
        renderer.SetBackground(0.7,0.7,0.7)
        # ... and set window size.
        renderWin.SetSize(400, 400)

        # Fuege Text am Nullpunkt hinzu:
        renderer.AddActor(textActor)
        
        # A simple function to be called when the user decides to quit the application.
        def exitCheck(obj, event):
            if obj.GetEventPending() != 0:
                obj.SetAbortRender(1)

        # Tell the application to use the function as an exit check.
        renderWin.AddObserver("AbortCheckEvent", exitCheck)

        renderInteractor.Initialize()
        # Because nothing will be rendered without any input, we order the first render manually before control is handed over to the main-loop.
        renderWin.Render()
        renderInteractor.Start()
コード例 #55
0
ファイル: LensDisk.py プロジェクト: dcasbol/HysTrainer
	def Initialize(self):
		"""Prepare the class to work."""

		self.Initialized = True
		
		# Radius
		self.r = r = 0.1
		
		# Disk
		self.diskSrc = diskSrc = vtk.vtkDiskSource()
		diskSrc.SetCircumferentialResolution(50)
		diskSrc.SetInnerRadius(r)
		diskSrc.SetOuterRadius(3*r)
		diskSrc.Update()
		
		# Lens Triangle
		self.trianglePoints = trianglePoints = vtk.vtkPoints()
		trianglePoints.InsertNextPoint(0,-r*0.9,0)
		trianglePoints.InsertNextPoint(-r*0.05,-r,0)
		trianglePoints.InsertNextPoint(r*0.05,-r,0)
		
		self.triangleSrc = triangleSrc = vtk.vtkTriangle()
		for i in range(3):
			triangleSrc.GetPointIds().SetId(i,i)
			
		self.triangleCells = triangleCells = vtk.vtkCellArray()
		triangleCells.InsertNextCell(triangleSrc)
		
		self.trianglePD = trianglePD = vtk.vtkPolyData()
		trianglePD.SetPoints(trianglePoints)
		trianglePD.SetPolys(triangleCells)
		
		# Mappers
		self.diskMapper = diskMapper = vtk.vtkPolyDataMapper()
		diskMapper.SetInputConnection(diskSrc.GetOutputPort())
		
		self.triangleMapper = triangleMapper = vtk.vtkPolyDataMapper()
		triangleMapper.SetInput(trianglePD)
		
		# Actors
		self.diskActor = diskActor = vtk.vtkFollower()
		diskActor.SetMapper(diskMapper)
		diskActor.GetProperty().SetColor(0,0,0)
		
		self.triangleActor = triangleActor = vtk.vtkFollower()
		triangleActor.SetMapper(triangleMapper)
		triangleActor.GetProperty().SetColor(0,0,0)
		
		# Positioning
		self.cam = self.sc.GetCamera()
		self.p = self.cam.GetPosition()
		self.d = d = self.cam.GetDirectionOfProjection()
		factor = 0.2
		diskActor.AddPosition(self.p[0] + factor*d[0], \
			self.p[1] + factor*d[1], self.p[2] + factor*d[2])
		triangleActor.AddPosition(self.p[0] + factor*d[0], \
			self.p[1] + factor*d[1], self.p[2] + factor*d[2])
		
		self.ren = ren = self.sc.GetRenderWindow().GetRenderers().GetFirstRenderer()
		ren.AddActor(diskActor)
		ren.AddActor(triangleActor)
		diskActor.SetCamera(self.cam)
		triangleActor.SetCamera(self.cam)
コード例 #56
0
ファイル: WidgetTest.py プロジェクト: NESII/uvcdat
# Create the axes and the associated mapper and actor.
axes = vtk.vtkAxes()
axes.SetOrigin(0, 0, 0)
axesMapper = vtk.vtkPolyDataMapper()
axesMapper.SetInputConnection(axes.GetOutputPort())
axesActor = vtk.vtkActor()
axesActor.SetMapper(axesMapper)

# Create the 3D text and the associated mapper and follower (a type of
# actor).  Position the text so it is displayed over the origin of the
# axes.
atext = vtk.vtkVectorText()
atext.SetText("Origin")
textMapper = vtk.vtkPolyDataMapper()
textMapper.SetInputConnection(atext.GetOutputPort())
textActor = vtk.vtkFollower()
textActor.SetMapper(textMapper)
textActor.SetScale(0.1, 0.1, 0.1)

buttonRepresentation = vtk.vtkProp3DButtonRepresentation()
#buttonRepresentation.FollowCameraOn()
buttonRepresentation.SetNumberOfStates(1)
buttonRepresentation.SetButtonProp( 0, textActor )


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