示例#1
1
def makeTextCaption(text,size,labPos,attPos):
    coneGlyph = vtk.vtkConeSource()
    coneGlyph.SetResolution(10)
    coneGlyph.SetHeight(150)
    coneGlyph.SetRadius(50)
    coneGlyph.Update()
    glyphMaxSize = 50
    glyphSize = .1

    capt = vtk.vtkCaptionActor2D()
    capt.BorderOff()
    capt.SetCaption(text)
    capt.GetCaptionTextProperty().SetFontSize(size)
    capt.GetCaptionTextProperty().BoldOn()
    capt.GetCaptionTextProperty().ItalicOff()
    capt.GetCaptionTextProperty().ShadowOff()
    capt.SetAttachmentPoint(attPos)
    capt.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport()
    capt.GetPositionCoordinate().SetReferenceCoordinate(None)
    capt.GetPositionCoordinate().SetValue(labPos)
    capt.SetWidth(0.013*(len(text)+1))
    capt.SetHeight(0.1)
    capt.ThreeDimensionalLeaderOff()
    capt.SetLeaderGlyph(coneGlyph.GetOutput())
    capt.SetMaximumLeaderGlyphSize(glyphMaxSize)
    capt.SetLeaderGlyphSize(glyphSize)
    capt.GetProperty().SetColor(0,0,0)
    capt.GetProperty().SetLineWidth(5)

    return capt
 def __init__(self):
     '''
     Constructor
     '''
     self.__Caption = vtk.vtkCaptionActor2D()
     
     self.SetAlign(False)
     self.GetLineProperty().SetColor(0.85,0.85,1)
     self.GetHandleProperty().SetColor (0.75,0.75,1)
     
     self.KeyPressActivationOff()
     
     self.__Caption.SetAttachmentPoint(0, 0, 0)
     self.__Caption.SetCaption(".")
     self.__Caption.GetCaptionTextProperty().SetColor (0.7, 0.7, 0)
     self.__Caption.GetCaptionTextProperty().ShadowOff()
     self.__Caption.GetCaptionTextProperty().BoldOn()
     self.__Caption.GetCaptionTextProperty().ItalicOn()
     self.__Caption.GetTextActor().SetTextScaleModeToNone()
     self.__Caption.GetCaptionTextProperty().SetFontSize(15)
     self.__Caption.SetLeaderGlyphSize(0.05)
     self.__Caption.BorderOff()
     self.__Caption.SetPadding(5)
     
     self.__State = self.Start
     self.AddObserver("MouseMoveEvent", self.OnMouseMove)
     self.AddObserver("StartInteractionEvent", self.OnStart)
     self.AddObserver("EndInteractionEvent", self.OnEnd)
    def _MakeActors(self):
        # create the original marker
        actors = SphereMarkFactory.SphereMarkFactory._MakeActors(self)

        # now append a caption actor
        self._captionActor = vtk.vtkCaptionActor2D()
        self._captionActor.SetAttachmentPoint(self.GetPosition())
        self._captionActor.SetCaption(self.GetCaption())
        self._captionActor.SetThreeDimensionalLeader(False)
        self._captionActor.SetWidth(0.25 / 3.0)
        self._captionActor.SetHeight(0.10 / 3.0)
        self._captionActor.SetVisibility(self.bCaptionVisibility)

        text_actor = self._captionActor.GetTextActor()
        # text_actor.SetTextScaleModeToNone()  # set absolute scaling mode

        p = self._captionActor.GetCaptionTextProperty()
        p.SetColor((0, 1, 0.2))
        p.BoldOff()
        p.ItalicOff()
        p.SetFontSize(15)
        p.ShadowOff()

        actors.append(self._captionActor)

        return actors
    def _MakeActors(self):
        # create the original marker
        actors = SphereMarkFactory.SphereMarkFactory._MakeActors(self)

        # now append a caption actor
        self._captionActor = vtk.vtkCaptionActor2D()
        self._captionActor.SetAttachmentPoint(self.GetPosition())
        self._captionActor.SetCaption(self.GetCaption())
        self._captionActor.SetThreeDimensionalLeader(False)
        self._captionActor.SetWidth(0.25 / 3.0)
        self._captionActor.SetHeight(0.10 / 3.0)
        self._captionActor.SetVisibility(self.bCaptionVisibility)

        text_actor = self._captionActor.GetTextActor()
        # text_actor.SetTextScaleModeToNone()  # set absolute scaling mode

        p = self._captionActor.GetCaptionTextProperty()
        p.SetColor((0, 1, 0.2))
        p.BoldOff()
        p.ItalicOff()
        p.SetFontSize(15)
        p.ShadowOff()

        actors.append(self._captionActor)

        return actors
示例#5
0
def pointer(x, y, z, radius):
    # cast the positions to text so they can be added as labels
    labelX = str(x)
    labelY = str(y)
    labelZ = str(z)

    # Create sphere
    sphere_source = vtk.vtkSphereSource()
    sphere_source.SetCenter(x, y, z)
    sphere_source.SetRadius(radius)
    sphere_source.Update()

    # Create the caption to show the sphere position
    caption = vtk.vtkCaptionActor2D()
    caption.SetCaption("(" + labelX + ", " + labelY + ", " + labelZ + ")")

    # Set the size of the caption box. The box is measured from the lower left corner to the upper right corner.
    # SetWidth and SetHeight are defined as fraction of the viewport.  So SetWidth(0.1) sets the caption box
    # to 10% the width of the viewport.
    # The caption text will then fill the provided caption box as best possible
    caption.SetWidth(0.15)
    caption.SetHeight(0.02)

    caption.GetProperty().SetColor(colours['captionColour'])
    caption.SetAttachmentPoint(sphere_source.GetCenter())

    # Formatting of the text possible with vtkTextProperty
    # Disable the border box for the caption
    caption.BorderOff()

    # Map texture coordinates of the cube_source
    map_to_plane = vtk.vtkTextureMapToPlane()
    map_to_plane.SetInputConnection(sphere_source.GetOutputPort())

    # Create polydatamapper and set the mapped texture as input
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(map_to_plane.GetOutputPort())
    # Create actor and set the mapper and the texture . uncomment if no texture
    #  mapper = vtk.vtkPolyDataMapper()
    # mapper.SetInputConnection(cube_source.GetOutputPort())
    mapper.Update()

    # create the sphere actor with the mapper
    sphere = vtk.vtkActor()
    sphere.SetMapper(mapper)
    sphere.GetProperty().SetColor(colours['pointer'])

    # Assemble the cube and annotations into a complete prop actor.
    pointer = vtk.vtkPropAssembly()
    pointer.AddPart(sphere)
    pointer.AddPart(caption)

    # actor.SetTexture(texture)

    return pointer
示例#6
0
 def _createCaptionActor(self):
     actor = vtk.vtkCaptionActor2D()
     actor.SetCaption(self._name)
     actor.SetPosition(25., 25.)
     actor.SetWidth(0.5)
     actor.SetHeight(0.05)
     actor.SetVisibility(False)
     actor.BorderOff()
     actor.ThreeDimensionalLeaderOff()
     actor.LeaderOn()
     return actor
示例#7
0
def load_altitude_actor():
    text_actor = vtk.vtkCaptionActor2D()
    text_actor.SetCaption("")

    # Formatting
    text_actor.GetCaptionTextProperty().SetColor( 1.0, 1.0, 1.0 )
    text_actor.GetCaptionTextProperty().SetOpacity(0.9)
    text_actor.ThreeDimensionalLeaderOn()
    

    return text_actor
示例#8
0
    def __buildPPS(self):
        self._pps_actors = {}
        self._pps_caption_actors = {}
        pps_list = self._load_thread.getPPS()
        for name, pps in pps_list.items():
            src = vtk.vtkSphereSource()
            pt = pps['point']
            src.SetCenter(pt)
            src.SetRadius(0.02)
            src.SetPhiResolution(16)
            src.SetThetaResolution(16)

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

            actor = vtk.vtkActor()
            actor.SetMapper(mapper)
            actor.VisibilityOff()

            property = actor.GetProperty()
            property.SetColor([1, 0, 1])
            property.SetAmbient(0.4)
            property.SetDiffuse(0.6)

            self._pps_actors[name] = actor
            self._vtk_renderer.AddViewProp(actor)

            caption_actor = vtk.vtkCaptionActor2D()
            caption_actor.SetAttachmentPoint(pt)
            caption_actor.SetCaption(name)
            caption_actor.SetPosition(25., 75.)
            caption_actor.SetWidth(0.5)
            caption_actor.SetHeight(0.05)
            caption_actor.SetVisibility(False)
            caption_actor.BorderOff()
            caption_actor.ThreeDimensionalLeaderOff()
            caption_actor.LeaderOn()

            property = caption_actor.GetProperty()
            property.SetColor([0, 0, 0])

            text_actor = caption_actor.GetTextActor()
            text_actor.SetTextScaleModeToViewport()

            property = caption_actor.GetCaptionTextProperty()
            property.SetColor([0, 0, 0])
            property.BoldOff()
            property.ItalicOff()
            property.SetFontSize(3)
            property.ShadowOff()

            self._pps_caption_actors[name] = caption_actor
            self._vtk_renderer.AddViewProp(caption_actor)
def label_series(labels,
                 image_width,
                 image_height,
                 text_orientation="vertical",
                 background_color=[0, 0, 0]):
    '''not yet tested, might not work'''
    label_images = []
    for label in labels:
        text_actor = vtk.vtkCaptionActor2D()
        text_actor.SetAttachmentPoint(
            (0.0, -0.15, 0.0))  #position relative to center of screen
        text_actor.SetPosition(0, 0)  #position relative to attachment point
        text_actor.SetCaption(str(label))
        text_actor.GetCaptionTextProperty().SetJustificationToLeft()
        text_actor.GetCaptionTextProperty().SetFontSize(24)
        text_actor.GetCaptionTextProperty().SetVerticalJustificationToCentered(
        )
        text_actor.GetCaptionTextProperty().UseTightBoundingBoxOn()
        # #         text_actor.GetTextActor().SetTextScaleModeToProp()
        text_actor.GetTextActor().SetTextScaleModeToViewport(
        )  #This seems to work best?
        #         text_actor.GetTextActor().SetTextScaleModeToNone()
        text_actor.BorderOff()
        text_actor.GetCaptionTextProperty().SetVerticalJustificationToCentered(
        )
        text_actor.GetCaptionTextProperty().SetOrientation(90)

        label_renWin = simple_vtkRenderWindow(
            actors=[text_actor],
            render_dimensions=[image_width, image_height],
            background_color=background_color,
            display_window=False)
        label_iren = label_renWin.GetInteractor()
        if label_iren.GetInitialized() == 0:
            label_iren.Initialize()
        label_renderer = label_renWin.GetRenderers().GetFirstRenderer()
        label_renWin.OffScreenRenderingOn()

        #grab and append image
        image_filter = vtk.vtkWindowToImageFilter()
        image_filter.SetInput(label_renWin)
        image_filter.Modified()
        image_filter.Update()
        label_images.append(image_filter.GetOutput())

        #clean up resources
        del image_filter
        label_renWin.Finalize()
        label_iren.TerminateApp()
        del label_renWin, label_iren

    return label_images
示例#10
0
 def showPosition(self, lat, lon, txt='Position'):
     s = self.addPart(ObjectBase(vtk.vtkSphereSource()))
     s._source.SetRadius(0.005)
     s._source.SetCenter(0.5, 0, 0)
     s._actor.GetProperty().SetColor(1.0, 0, 0)
     s._actor.RotateWXYZ(-lat, 0, 1, 0)
     s._actor.RotateWXYZ(lon, 0, 0, 1)
     c = vtk.vtkCaptionActor2D()
     c.SetCaption(txt)
     c.SetWidth(0.1)
     c.SetHeight(0.04)
     c.SetAttachmentPoint(s._actor.GetCenter())
     return c
示例#11
0
    def _create_actors(self):

        # 1. create really small 3D cursor to place at relevant point
        d = 2  # 2 mm dimension
        cs = vtk.vtkCursor3D()
        cs.AllOff()
        cs.AxesOn()
        cs.SetModelBounds(-d, +d, -d, +d, -d, +d)
        cs.SetFocalPoint(0, 0, 0)

        m = vtk.vtkPolyDataMapper()
        m.SetInput(cs.GetOutput())

        self.c3da = vtk.vtkActor()
        self.c3da.SetPickable(0)
        self.c3da.SetMapper(m)

        self.ren.AddActor(self.c3da)

        # 2. create caption actor with label
        ca = vtk.vtkCaptionActor2D()
        ca.GetProperty().SetColor(1, 1, 0)
        tp = ca.GetCaptionTextProperty()
        tp.SetColor(1, 1, 0)
        tp.ShadowOff()
        ca.SetPickable(0)
        ca.SetAttachmentPoint(0, 0, 0)  # we'll move this later
        ca.SetPosition(25, 10)
        ca.BorderOff()
        ca.SetWidth(0.3)
        ca.SetHeight(0.04)

        # this will be changed at the first property set
        ca.SetCaption('.')

        self.ca = ca
        self.ren.AddActor(ca)
示例#12
0
    def _create_actors(self):

        # 1. create really small 3D cursor to place at relevant point
        d = 2 # 2 mm dimension 
        cs = vtk.vtkCursor3D()
        cs.AllOff()
        cs.AxesOn()
        cs.SetModelBounds(-d, +d, -d, +d, -d, +d)
        cs.SetFocalPoint(0,0,0)

        m = vtk.vtkPolyDataMapper()
        m.SetInput(cs.GetOutput())

        self.c3da = vtk.vtkActor()
        self.c3da.SetPickable(0)
        self.c3da.SetMapper(m)

        self.ren.AddActor(self.c3da)

        # 2. create caption actor with label
        ca = vtk.vtkCaptionActor2D()
        ca.GetProperty().SetColor(1,1,0)
        tp = ca.GetCaptionTextProperty()
        tp.SetColor(1,1,0)
        tp.ShadowOff()
        ca.SetPickable(0)
        ca.SetAttachmentPoint(0,0,0) # we'll move this later
        ca.SetPosition(25,10)
        ca.BorderOff()
        ca.SetWidth(0.3)
        ca.SetHeight(0.04)

        # this will be changed at the first property set
        ca.SetCaption('.')

        self.ca = ca
        self.ren.AddActor(ca)
示例#13
0
    def _storePoint(self, discrete, world, value, pointName,
                    lockToSurface=False, boundsForPoints=None):

        tdren = self.slice3dVWR._threedRenderer
        tdrwi = self.slice3dVWR.threedFrame.threedRWI

        if not boundsForPoints:
            bounds = tdren.ComputeVisiblePropBounds()
        else:
            bounds = boundsForPoints

        if bounds[1] - bounds[0] <= 0 or \
           bounds[3] - bounds[2] <= 0 or \
           bounds[5] - bounds[4] <= 0:
            bounds = (-1,1,-1,1,-1,1)
        

        # we use a pointwidget
        pw = vtk.vtkPointWidget()
        #pw.SetInput(inputData)
        pw.PlaceWidget(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4],
                       bounds[5])
        pw.SetPosition(world)
        # make priority higher than the default of vtk3DWidget so
        # that imageplanes behind us don't get selected the whole time
        pw.SetPriority(0.6)
        pw.SetInteractor(tdrwi)
        pw.AllOff()
        pw.On()

        #ss.SetRadius((bounds[1] - bounds[0]) / 100.0)
        
        ca = vtk.vtkCaptionActor2D()
        ca.GetProperty().SetColor(1,1,0)
        tp = ca.GetCaptionTextProperty()
        tp.SetColor(1,1,0)
        tp.ShadowOff()
        ca.SetPickable(0)
        ca.SetAttachmentPoint(world)
        ca.SetPosition(25,10)
        ca.BorderOff()
        ca.SetWidth(0.3)
        ca.SetHeight(0.04)
        # I used to have the problem on my ATI X1600 that interaction
        # was extremely slow of 3D was on... problem seems to have
        # gone away by itself, or it rather has to do with the slow-
        # glcontext-things
        ca.ThreeDimensionalLeaderOn()
        ca.SetMaximumLeaderGlyphSize(10)
        ca.SetLeaderGlyphSize(0.025)

        coneSource = vtk.vtkConeSource()
        coneSource.SetResolution(6)
        # we want the cone's very tip to by at 0,0,0
        coneSource.SetCenter(- coneSource.GetHeight() / 2.0, 0, 0)

        ca.SetLeaderGlyph(coneSource.GetOutput())

        if len(pointName) > 0:
            ca.SetCaption(pointName)
        else:
            ca.SetCaption(".")
            # since VTK 20070628, caption actor doesn't like an empty label

        tdren.AddActor(ca)


        def pw_ei_cb(pw, evt_name):
            # make sure our output is good
            self._syncOutputSelectedPoints()

        pw.AddObserver('StartInteractionEvent', lambda pw, evt_name,
                       s=self:
                       s._observerPointWidgetInteraction(pw, evt_name))
        pw.AddObserver('InteractionEvent', lambda pw, evt_name,
                       s=self:
                       s._observerPointWidgetInteraction(pw, evt_name))
        pw.AddObserver('EndInteractionEvent', pw_ei_cb)

        # we start with it disabled
        pw.Off()

        # store the cursor (discrete coords) the coords and the actor
        self._pointsList.append({'discrete' : tuple(discrete),
                                 'world' : tuple(world),
                                 'value' : value,
                                 'name' : pointName,
                                 'pointWidget' : pw,
                                 'lockToSurface' : lockToSurface,
                                 'sphereActor' : ca})

        self._grid.AppendRows()
        #self._grid.AdjustScrollBars()
        row = self._grid.GetNumberRows() - 1
        self._syncGridRowToSelPoints(row)
        
        # make sure self._outputSelectedPoints is up to date
        self._syncOutputSelectedPoints()

        self.slice3dVWR.render3D()
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
sphere = vtk.vtkSphereSource()
sphereMapper = vtk.vtkPolyDataMapper()
sphereMapper.SetInputConnection(sphere.GetOutputPort())
sphereActor = vtk.vtkActor()
sphereActor.SetMapper(sphereMapper)
coneGlyph = vtk.vtkConeSource()
coneGlyph.SetResolution(6)
sphereGlyph = vtk.vtkSphereSource()
sphereGlyph.SetThetaResolution(12)
sphereGlyph.SetPhiResolution(6)
caption = vtk.vtkCaptionActor2D()
caption.SetCaption("This is the\nsouth pole")
caption.SetAttachmentPoint(0,0,-0.5)
caption.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport()
caption.GetPositionCoordinate().SetReferenceCoordinate(None)
caption.GetPositionCoordinate().SetValue(0.05,0.05)
caption.SetWidth(0.25)
caption.SetHeight(0.15)
caption.ThreeDimensionalLeaderOn()
caption.SetLeaderGlyphConnection(coneGlyph.GetOutputPort())
caption.SetMaximumLeaderGlyphSize(10)
caption.SetLeaderGlyphSize(0.025)
caption.GetProperty().SetColor(1,0,0)
tprop = caption.GetCaptionTextProperty()
tprop.SetColor(caption.GetProperty().GetColor())
caption2 = vtk.vtkCaptionActor2D()
示例#15
0
    def _storePoint(self,
                    discrete,
                    world,
                    value,
                    pointName,
                    lockToSurface=False,
                    boundsForPoints=None):

        tdren = self.slice3dVWR._threedRenderer
        tdrwi = self.slice3dVWR.threedFrame.threedRWI

        if not boundsForPoints:
            bounds = tdren.ComputeVisiblePropBounds()
        else:
            bounds = boundsForPoints

        if bounds[1] - bounds[0] <= 0 or \
           bounds[3] - bounds[2] <= 0 or \
           bounds[5] - bounds[4] <= 0:
            bounds = (-1, 1, -1, 1, -1, 1)

        # we use a pointwidget
        pw = vtk.vtkPointWidget()
        #pw.SetInput(inputData)
        pw.PlaceWidget(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4],
                       bounds[5])
        pw.SetPosition(world)
        # make priority higher than the default of vtk3DWidget so
        # that imageplanes behind us don't get selected the whole time
        pw.SetPriority(0.6)
        pw.SetInteractor(tdrwi)
        pw.AllOff()
        pw.On()

        #ss.SetRadius((bounds[1] - bounds[0]) / 100.0)

        ca = vtk.vtkCaptionActor2D()
        ca.GetProperty().SetColor(1, 1, 0)
        tp = ca.GetCaptionTextProperty()
        tp.SetColor(1, 1, 0)
        tp.ShadowOff()
        ca.SetPickable(0)
        ca.SetAttachmentPoint(world)
        ca.SetPosition(25, 10)
        ca.BorderOff()
        ca.SetWidth(0.3)
        ca.SetHeight(0.04)
        # I used to have the problem on my ATI X1600 that interaction
        # was extremely slow of 3D was on... problem seems to have
        # gone away by itself, or it rather has to do with the slow-
        # glcontext-things
        ca.ThreeDimensionalLeaderOn()
        ca.SetMaximumLeaderGlyphSize(10)
        ca.SetLeaderGlyphSize(0.025)

        coneSource = vtk.vtkConeSource()
        coneSource.SetResolution(6)
        # we want the cone's very tip to by at 0,0,0
        coneSource.SetCenter(-coneSource.GetHeight() / 2.0, 0, 0)

        ca.SetLeaderGlyph(coneSource.GetOutput())

        if len(pointName) > 0:
            ca.SetCaption(pointName)
        else:
            ca.SetCaption(".")
            # since VTK 20070628, caption actor doesn't like an empty label

        tdren.AddActor(ca)

        def pw_ei_cb(pw, evt_name):
            # make sure our output is good
            self._syncOutputSelectedPoints()

        pw.AddObserver('StartInteractionEvent',
                       lambda pw, evt_name, s=self: s.
                       _observerPointWidgetInteraction(pw, evt_name))
        pw.AddObserver('InteractionEvent',
                       lambda pw, evt_name, s=self: s.
                       _observerPointWidgetInteraction(pw, evt_name))
        pw.AddObserver('EndInteractionEvent', pw_ei_cb)

        # we start with it disabled
        pw.Off()

        # store the cursor (discrete coords) the coords and the actor
        self._pointsList.append({
            'discrete': tuple(discrete),
            'world': tuple(world),
            'value': value,
            'name': pointName,
            'pointWidget': pw,
            'lockToSurface': lockToSurface,
            'sphereActor': ca
        })

        self._grid.AppendRows()
        #self._grid.AdjustScrollBars()
        row = self._grid.GetNumberRows() - 1
        self._syncGridRowToSelPoints(row)

        # make sure self._outputSelectedPoints is up to date
        self._syncOutputSelectedPoints()

        self.slice3dVWR.render3D()
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Create a test pipeline
ss = vtk.vtkSphereSource()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(ss.GetOutput())
actor = vtk.vtkActor()
actor.SetMapper(mapper)

# Create the widget and its representation
rep = vtk.vtkCaptionActor2D()
rep.SetCaption("This is a test\nAnd it has two lines")
rep.GetTextActor().GetTextProperty().SetJustificationToCentered()
rep.GetTextActor().GetTextProperty().SetVerticalJustificationToCentered()

widget = vtk.vtkCaptionWidget()
widget.SetInteractor(iren)
widget.SetCaptionActor2D(rep)

# Add the actors to the renderer, set the background and size
ren1.AddActor(actor)
ren1.SetBackground(0.1, 0.2, 0.4)
renWin.SetSize(300, 300)

# record events
recorder = vtk.vtkInteractorEventRecorder()
示例#17
0
def toggleCaptions(renwinRef, renderers, blocks, showCoordsRef, progressBarRef,
                   key):
    # Activates on keypress "c"
    # If the key is used, switch the status of the checkbox
    if (key == 'key'):
        if (showCoordsRef.isChecked() == True):
            showCoordsRef.setChecked(False)
        else:
            showCoordsRef.setChecked(True)

    progressBarRef.setProperty("value", 0)
    iteration = 0

    if showCoordsRef.isChecked() == True:
        wallCoordinates, _, _ = scanScene.get_wall_positions(renderers, blocks)
        maxLength, maxWidth, _, _ = scanScene.get_scene_bounds(
            renderers, blocks)

        for x in range(maxLength + 1):
            for z in range(maxWidth + 1):
                subList = [
                    point for point in wallCoordinates
                    if point[0] == x and point[2] == z
                ]
                sortedSubList = sorted(subList,
                                       key=lambda k: [k[1]],
                                       reverse=True)
                if len(sortedSubList) > 0:
                    picker = vtkPropPicker()
                    propPicked = picker.Pick3DPoint(sortedSubList[0],
                                                    renderers[blocks])
                    targetProp = picker.GetViewProp()
                    caption = vtkCaptionActor2D()
                    caption.SetCaption("(" + str(x) + ", " + str(z) + ")")
                    caption.SetWidth(0.15)
                    caption.SetHeight(0.02)
                    caption.GetProperty().SetColor(colours['captionColour'])
                    caption.SetAttachmentPoint(x, sortedSubList[0][1] + 0.4, z)
                    caption.BorderOff()
                    targetProp.AddPart(caption)
    else:
        # Remove all captions
        wallProps = scanScene.get_wall_props(renderers, blocks)
        numberProps = len(wallProps)
        for currentProp in wallProps:
            numberOfActors = currentProp.GetNumberOfPaths()

            # setup a vtkPropAssembly to store the assembly of parts that make up the current prop, and populate it
            actorCollection = vtkPropAssembly()
            actorCollection = currentProp.GetParts()

            # and initiate traversal over the collection of parts/actors
            actorCollection.InitTraversal()
            for actor in range(numberOfActors):
                # now iterate over each actor
                # move to the next actor in the collection
                currentActor = actorCollection.GetNextProp()
                # check if this actor is a caption type, and if so then set its opacity based on the checkbox and "height"
                # method returns a 1 if the type of the actor matches the argument, otherwise returns a 0
                typeBool = currentActor.IsTypeOf("vtkCaptionActor2D")
                if typeBool == 1:
                    # this actor is a caption type, so remove it
                    currentProp.RemovePart(currentActor)

    renwinRef.Render()
    return
示例#18
0
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
sphere = vtk.vtkSphereSource()
sphereMapper = vtk.vtkPolyDataMapper()
sphereMapper.SetInputConnection(sphere.GetOutputPort())
sphereActor = vtk.vtkActor()
sphereActor.SetMapper(sphereMapper)
coneGlyph = vtk.vtkConeSource()
coneGlyph.SetResolution(6)
sphereGlyph = vtk.vtkSphereSource()
sphereGlyph.SetThetaResolution(12)
sphereGlyph.SetPhiResolution(6)
caption = vtk.vtkCaptionActor2D()
caption.SetCaption("This is the\nsouth pole")
caption.SetAttachmentPoint(0,0,-0.5)
caption.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport()
caption.GetPositionCoordinate().SetReferenceCoordinate(None)
caption.GetPositionCoordinate().SetValue(0.05,0.05)
caption.SetWidth(0.25)
caption.SetHeight(0.15)
caption.ThreeDimensionalLeaderOn()
caption.SetLeaderGlyphConnection(coneGlyph.GetOutputPort())
caption.SetMaximumLeaderGlyphSize(10)
caption.SetLeaderGlyphSize(0.025)
caption.GetProperty().SetColor(1,0,0)
tprop = caption.GetCaptionTextProperty()
tprop.SetColor(caption.GetProperty().GetColor())
caption2 = vtk.vtkCaptionActor2D()
def rotation_series(render_window,
                    rotations=3,
                    rotation_axis="azimuth",
                    append_ID=True,
                    series_name='',
                    label_background=[0, 1, 0],
                    label_font_size=10,
                    label_color=[1, 0, 0],
                    label_orientation='vertical'):
    '''
    Collect a series of images as a camera rotates around an object. 
    
    Parameters
    ----------
    renderWindow : vtk.vtkRenderWindow
        Window to manipulate and grab images from
    rotationAxis : str
        accepts azimuth or elevation
    rotationNumber : int
        number of images to generate
    '''
    iren = render_window.GetInteractor()
    if iren.GetInitialized() == 0:
        iren.Initialize()
    render_window.OffScreenRenderingOn()
    renderer = render_window.GetRenderers().GetFirstRenderer()
    camera = renderer.GetActiveCamera()

    images = []

    if append_ID:
        text_actor = vtk.vtkCaptionActor2D()
        text_actor.SetAttachmentPoint(
            (0.0, -0.15, 0.0))  #position relative to center of screen
        text_actor.SetPosition(0, 0)  #position relative to attachment point
        text_actor.SetCaption(str(series_name))
        text_actor.GetCaptionTextProperty().SetJustificationToLeft()
        text_actor.GetCaptionTextProperty().SetFontSize(24)
        text_actor.GetCaptionTextProperty().SetVerticalJustificationToCentered(
        )
        text_actor.GetCaptionTextProperty().UseTightBoundingBoxOn()
        # #         text_actor.GetTextActor().SetTextScaleModeToProp()
        text_actor.GetTextActor().SetTextScaleModeToViewport(
        )  #This seems to work best?
        #         text_actor.GetTextActor().SetTextScaleModeToNone()
        text_actor.BorderOff()
        text_actor.GetCaptionTextProperty().SetVerticalJustificationToCentered(
        )
        text_actor.GetCaptionTextProperty().SetOrientation(90)

        #build renderwindow
        size = render_window.GetSize(
        )  #I might make it so it is smaller in one dimension
        label_dimensions = []
        if label_orientation == 'vertical':
            label_dimensions = [int(0.1 * size[0]), size[1]]
        else:
            label_dimensions = [size[0], int(0.1 * size[1])]
        label_renWin = simple_vtkRenderWindow(
            actors=[text_actor],
            render_dimensions=label_dimensions,
            background_color=[0, 0, 1],
            display_window=False)
        label_iren = label_renWin.GetInteractor()
        if label_iren.GetInitialized() == 0:
            label_iren.Initialize()
        label_renderer = label_renWin.GetRenderers().GetFirstRenderer()
        label_renWin.OffScreenRenderingOn()

        #grab and append image
        image_filter = vtk.vtkWindowToImageFilter()
        image_filter.SetInput(label_renWin)
        image_filter.Modified()
        image_filter.Update()
        images.append(image_filter.GetOutput())

        #clean up resources
        del image_filter
        label_renWin.Finalize()
        label_iren.TerminateApp()
        del label_renWin, label_iren

    #rotation images
    for x in range(rotations):
        image_filter = vtk.vtkWindowToImageFilter()
        image_filter.SetInput(render_window)
        image_filter.Modified()
        image_filter.Update()
        images.append(image_filter.GetOutput())
        if rotation_axis == 'azimuth':
            camera.Azimuth(360 / rotations)
        elif rotation_axis == 'elevation':
            camera.Elevation(360 / rotations)
        del image_filter

    return images