def PlaneSphereActors():
    ps = vtk.vtkPlaneSource()
    ps.SetXResolution(10)
    ps.SetYResolution(10)

    ss = vtk.vtkSphereSource()
    ss.SetRadius (0.3)

    group = vtk.vtkMultiBlockDataGroupFilter()
    group.AddInputConnection(ps.GetOutputPort())
    group.AddInputConnection(ss.GetOutputPort())

    ag = vtk.vtkRandomAttributeGenerator()
    ag.SetInputConnection(group.GetOutputPort())
    ag.GenerateCellScalarsOn()
    ag.AttributesConstantPerBlockOn()

    n = vtk.vtkPolyDataNormals()
    n.SetInputConnection(ag.GetOutputPort())
    n.Update ();

    actors = []
    it = n.GetOutputDataObject(0).NewIterator()
    it.InitTraversal()
    while not it.IsDoneWithTraversal():
        pm = vtk.vtkPolyDataMapper()
        pm.SetInputData(it.GetCurrentDataObject())

        a = vtk.vtkActor()
        a.SetMapper(pm)
        actors.append (a)
        it.GoToNextItem()
    return actors
Ejemplo n.º 2
0
 def __init__( self ):
   PerkEvaluatorMetric.__init__( self )
   
   self.outputPolyData = vtk.vtkAppendPolyData()
   
   self.planeSource = vtk.vtkPlaneSource()
   self.planePolyData = self.planeSource.GetOutput()
Ejemplo n.º 3
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkPlaneSource(), 'Processing.',
         (), ('vtkPolyData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
Ejemplo n.º 4
0
    def __init__(self, name, sliceDirections, defaultPlaneOrientation=2):
        self.sliceDirections = sliceDirections
        self._defaultPlaneOrientation = 2

        # orthoPipeline is a list of dictionaries.  each dictionary is:
        # {'planeSource' : vtkPlaneSource, 'planeActor' : vtkActor,
        #  'textureMapToPlane' : vtkTextureMapToPlane,
        #  '
        self._orthoPipeline = []
        # this is the frame that we will use to display our slice pipeline
        self._orthoViewFrame = None
        #
        self._renderer = None

        # list of vtkImagePlaneWidgets (first is "primary", rest are overlays)
        self._ipws = []

        # then some state variables
        self._enabled = True
        self._interactionEnabled = True

        # list of objects that want to be contoured by this slice
        self._contourObjectsDict = {}

        self.overlayMode = 'greenOpacityRange'
        self.fusionAlpha = 0.4

        # we'll use this to store the polydata of our primary slice
        self._primaryCopyPlaneSource = vtk.vtkPlaneSource()
        self._primaryCopyPlaneSource.SetXResolution(64)
        self._primaryCopyPlaneSource.SetYResolution(64)
        self.primaryPolyData = self._primaryCopyPlaneSource.GetOutput()
Ejemplo n.º 5
0
    def __init__(self, parent = None):
        super(VTKFrame, self).__init__(parent)

        self.vtkWidget = QVTKRenderWindowInteractor(self)
        vl = QtGui.QVBoxLayout(self)
        vl.addWidget(self.vtkWidget)
        vl.setContentsMargins(0, 0, 0, 0)
 
        self.ren = vtk.vtkRenderer()
        self.ren.SetBackground(0.1, 0.2, 0.4)
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
 
        # Provide some geometry
        resolution = 8
        aPlane = vtk.vtkPlaneSource()
        aPlane.SetXResolution(resolution)
        aPlane.SetYResolution(resolution)

        # Create cell data
        cellData = vtk.vtkFloatArray()
        for i in range(resolution * resolution):
            cellData.InsertNextValue(i+1)

        # Create a lookup table to map cell data to colors
        lut = vtk.vtkLookupTable()
        tableSize = max(resolution*resolution+1, 10)
        lut.SetNumberOfTableValues(tableSize)
        lut.Build()

        # Fill in a few known colors, the rest will be generated if needed
        lut.SetTableValue(0     , 0     , 0     , 0, 1)# Black
        lut.SetTableValue(1, 0.8900, 0.8100, 0.3400, 1)# Banana
        lut.SetTableValue(2, 1.0000, 0.3882, 0.2784, 1)# Tomato
        lut.SetTableValue(3, 0.9608, 0.8706, 0.7020, 1)# Wheat
        lut.SetTableValue(4, 0.9020, 0.9020, 0.9804, 1)# Lavender
        lut.SetTableValue(5, 1.0000, 0.4900, 0.2500, 1)# Flesh
        lut.SetTableValue(6, 0.5300, 0.1500, 0.3400, 1)# Raspberry
        lut.SetTableValue(7, 0.9804, 0.5020, 0.4471, 1)# Salmon
        lut.SetTableValue(8, 0.7400, 0.9900, 0.7900, 1)# Mint
        lut.SetTableValue(9, 0.2000, 0.6300, 0.7900, 1)# Peacock

        aPlane.Update() #Force an update so we can set cell data
        aPlane.GetOutput().GetCellData().SetScalars(cellData)

        # Create a mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(aPlane.GetOutputPort())
        mapper.SetScalarRange(0, tableSize - 1)
        mapper.SetLookupTable(lut)
 
        # Create an actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
 
        self.ren.AddActor(actor)
        self.ren.ResetCamera()

        self._initialized = False
Ejemplo n.º 6
0
 def initSeedPoint(self):
     print "initializing SeedPoint"
     self.vtkSeeds = vtk.vtkPlaneSource()
     self.vtkSeeds.SetXResolution(4)
     self.vtkSeeds.SetYResolution(4)
     self.vtkSeeds.SetOrigin(0.0, 0.0, 0.0)
     self.vtkSeeds.SetPoint1(-10.0, -10.0, -10.0)
     self.vtkSeeds.SetPoint2(10.0, 10.0, 10.0)
        def coplanar(self):
            numSelected = EventHandler().get_num_selected()
            if numSelected !=3:
                error_msg("You must first select exactly 3 markers",
                          )
                return

            # SetNormal is missing from the 4.2 python API so this is
            # a long winded way of setting the pw to intersect 3
            # selected markers
            m1, m2, m3 = EventHandler().get_selected()

            p1 = m1.get_center()
            p2 = m2.get_center()
            p3 = m3.get_center()
            
            pw = pwo.get_pw()
            planeO = vtk.vtkPlaneSource()
            planeO.SetOrigin(pw.GetOrigin())
            planeO.SetPoint1(pw.GetPoint1())
            planeO.SetPoint2(pw.GetPoint2())
            planeO.Update()

            planeN = vtk.vtkPlaneSource()
            planeN.SetOrigin(p1)
            planeN.SetPoint1(p2)
            planeN.SetPoint2(p3)
            planeN.Update()

            normal = planeN.GetNormal()
            planeO.SetNormal(normal)
            planeO.SetCenter(
                (p1[0] + p2[0] + p3[0])/3,
                (p1[1] + p2[1] + p3[1])/3,
                (p1[2] + p2[2] + p3[2])/3,
                )
            planeO.Update()

            pwxyz = pwo.get_pwxyz()
            pw.SetOrigin(planeO.GetOrigin())
            pw.SetPoint1(planeO.GetPoint1())
            pw.SetPoint2(planeO.GetPoint2())
            pw.UpdatePlacement()
            pwo.update_plane()
            pwo.Render()
            pwxyz.Render()
Ejemplo n.º 8
0
    def __init__(self, center=(0,0,0), color=(0,0,1) ):
        self.src = vtk.vtkPlaneSource()
        #self.src.SetCenter(center)
        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInput(self.src.GetOutput())
        self.SetMapper(self.mapper)

        self.SetColor(color)
        self.SetOrigin(center)
Ejemplo n.º 9
0
 def __init__(self):
     # ODE initialization
     self.world = ode.World()
     self.world.setGravity(GRAVITY)
     self.world.setERP(ERP)
     self.world.setCFM(CFM)
     self.space = ode.Space()
     self.floor = ode.GeomPlane(self.space, (0.0,1.0,0.0), 0.0)
     self.jointGroup = ode.JointGroup()
     self.time = 0.0
     # VTK initialization
     self.renderer = vtk.vtkRenderer()
     self.renderer.SetBackground(102.0/255.0,204/255.0,1.0)
     self.window = vtk.vtkRenderWindow()
     self.window.SetSize(WINDOW_WIDTH,WINDOW_HEIGHT)
     self.window.AddRenderer(self.renderer)
     self.interactor = vtk.vtkRenderWindowInteractor()
     self.interactor.SetRenderWindow(self.window)
     self.axes = vtk.vtkAxesActor()
     self.axes.SetAxisLabels(0)
     transform = vtk.vtkTransform()
     transform.Scale(0.1,0.1,0.1)
     self.axes.SetUserTransform(transform)
     self.renderer.AddActor(self.axes)
     # Create ground plane visualization
     self.floorVisual = vtk.vtkPlaneSource()
     self.floorVisual.SetNormal((0.0,1.0,0.0))
     self.floorVisual.SetResolution(10,10)
     self.floorReader = vtk.vtkJPEGReader()
     self.floorReader.SetFileName(FLOOR_IMAGE)
     self.floorTexture = vtk.vtkTexture()
     transform = vtk.vtkTransform()
     transform.Scale(50.0,50.0,50.0)
     self.floorTexture.SetTransform(transform)
     self.floorTexture.SetInput(self.floorReader.GetOutput())
     self.floorMap = vtk.vtkTextureMapToPlane()
     self.floorMap.SetInput(self.floorVisual.GetOutput())
     self.floorMapper = vtk.vtkPolyDataMapper()
     self.floorMapper.SetInput(self.floorMap.GetOutput())
     self.floorActor = vtk.vtkActor()
     transform = vtk.vtkTransform()
     transform.Scale(100.0,100.0,100.0)
     self.floorActor.SetUserTransform(transform)
     self.floorActor.SetMapper(self.floorMapper)
     self.floorActor.SetTexture(self.floorTexture)
     self.renderer.AddActor(self.floorActor)
     # VTK camera setup
     self.camera = vtk.vtkCamera()
     self.renderer.SetActiveCamera(self.camera)
     self.cameraFocus = [0.0, 0.0, 0.0]
     self.cameraPos = [4.0, 2.5, 1.5]
     self.cameraOffset = [0.0,1.0,3.0]
     self.cameraRoll = 0.0
     # Keep track of the simulated bodies and robots
     self.bodies = []
     self.robots = []
     self.controllers = []
    def _MakeXYActors(self, reduce=1):
        # get a texture-mapped actor
        extent = self._ImageReslice.GetOutputExtent()
        origin = self._ImageReslice.GetOutputOrigin()
        spacing = self._ImageReslice.GetOutputSpacing()

        bounds = [origin[0] + spacing[0] * (extent[0] - 0.5),
                  origin[0] + spacing[0] * (extent[1] + 0.5),
                  origin[1] + spacing[1] * (extent[2] - 0.5),
                  origin[1] + spacing[1] * (extent[3] + 0.5),
                  origin[2] + spacing[2] * (extent[4] - 0.5),
                  origin[2] + spacing[2] * (extent[5] + 0.5)]

        for sliceNumber in range(extent[4], old_div((extent[5] + 1), reduce)):
            # the z position of the slice
            z = origin[2] + reduce * sliceNumber * spacing[2]

            plane = vtk.vtkPlaneSource()
            plane.SetXResolution(1)
            plane.SetYResolution(1)
            plane.SetOrigin(bounds[0], bounds[2], z)
            plane.SetPoint1(bounds[1], bounds[2], z)
            plane.SetPoint2(bounds[0], bounds[3], z)

            imageClip = vtk.vtkExtractVOI()
            imageClip.SetInput(self._ImageToStructuredPoints.GetOutput())
            imageClip.SetVOI(extent[0], extent[1],
                             extent[2], extent[3],
                             reduce * sliceNumber, reduce * sliceNumber)
            imageClip.ReleaseDataFlagOn()

            texture = vtk.vtkTexture()
            texture.SetQualityTo32Bit()
            texture.SetInput(imageClip.GetOutput())
            texture.RepeatOff()
            texture.InterpolateOn()
            texture.MapColorScalarsThroughLookupTableOff()

            for i in range(3):
                mapper = vtk.vtkPolyDataMapper()
                mapper.SetInput(plane.GetOutput())
                mapper.SetClippingPlanes(self._ClippingPlanes[i])

                actor = vtk.vtkActor()
                actor.SetMapper(mapper)
                actor.SetTexture(texture)
                actor.PickableOff()
                actor.SetProperty(self._PropertyXY)

                self._PlanesXY.append(plane)
                self._ImageClipsXY.append(imageClip)
                self._ActorsXY.append(actor)

        numberOfPlanes = (extent[5] - extent[4] + 1) / reduce * 3
        return self._ActorsXY[-numberOfPlanes:]
Ejemplo n.º 11
0
    def SetInput(self, imagedata):
        axes = PLANE_DATA[self.orientation][0] # "x", "y" or "z"
        colour = PLANE_DATA[self.orientation][1]
        
        #if self.orientation == SAGITAL:
        #    spacing = min(imagedata.GetSpacing())
        #    permute = vtk.vtkImagePermute()
        #    permute.SetInput(imagedata)
        #    permute.GetOutput().ReleaseDataFlagOn()
        #    permute.SetOutputSpacing(spacing, spacing, spacing)
        #    imagedata = permute.GetOutput()

        # Picker for enabling plane motion.
        # Allows selection of a cell by shooting a ray into graphics window
        picker = vtk.vtkCellPicker()
        picker.SetTolerance(0.005)
        picker.PickFromListOn()

        # 3D widget for reslicing image data.
        # This 3D widget defines a plane that can be interactively placed in an image volume.
        widget = vtk.vtkImagePlaneWidget()
        widget.SetInput(imagedata)
        widget.SetSliceIndex(self.index)
        widget.SetPicker(picker)
        widget.SetKeyPressActivationValue(axes)
        widget.SetInteractor(self.iren)
        widget.TextureVisibilityOff()
        widget.DisplayTextOff()
        widget.RestrictPlaneToVolumeOff()
        exec("widget.SetPlaneOrientationTo"+axes.upper()+"Axes()")
        widget.AddObserver("InteractionEvent",self.Update)
        self.widget = widget
        
        prop = widget.GetPlaneProperty()
        prop.SetColor(colour)

        # Syncronize coloured outline with texture appropriately
        source = vtk.vtkPlaneSource()
        source.SetOrigin(widget.GetOrigin())
        source.SetPoint1(widget.GetPoint1())
        source.SetPoint2(widget.GetPoint2())
        source.SetNormal(widget.GetNormal())
        self.source = source
        
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInput(source.GetOutput())

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.SetTexture(widget.GetTexture())
        actor.VisibilityOff()
        self.actor = actor

        self.render.AddActor(actor)
Ejemplo n.º 12
0
 def _create_geometry(self):
     self._plane_source = vtk.vtkPlaneSource()
     self._plane_source.SetNormal((0.0,0.0,1.0))
     self._plane_source.SetXResolution(1)
     self._plane_source.SetYResolution(1)
     m = vtk.vtkPolyDataMapper()
     m.SetInputConnection(self._plane_source.GetOutputPort())
     a = vtk.vtkActor()
     a.SetMapper(m)
     a.GetProperty().SetOpacity(0.3)
     a.GetProperty().SetColor(0.0, 0.0, 0.7)
     self.props = [a]
def MakePlane():
    '''
    Make a plane as the source.
    :return: vtkPolyData with normal and scalar data.
    '''
    source = vtk.vtkPlaneSource()
    source.SetOrigin(-10.0, -10.0, 0.0)
    source.SetPoint2(-10.0, 10.0, 0.0)
    source.SetPoint1(10.0, -10.0, 0.0)
    source.SetXResolution(20)
    source.SetYResolution(20)
    source.Update()
    return MakeElevations(source.GetOutput())
Ejemplo n.º 14
0
    def createPlaneActor(plane):
        center = plane.center()
        normal = plane.normal()

        source = vtk.vtkPlaneSource()
        source.SetCenter(center[0], center[1], center[2])
        source.SetNormal(normal[0], normal[1], normal[2])

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

        obj = vtk.vtkActor()
        obj.SetMapper(mapper)

        return obj
Ejemplo n.º 15
0
 def __init__(self, origin, p1, p2, width, height):
     logging.debug("In Slice::__init__()")
     self._p1 = p1
     self._p2 = p2    
     self._width = width
     self._origin = origin
     self._height = height
     self._plane  = vtk.vtkPlaneSource()
     self._plane.SetOrigin(self._origin)
     self._plane.SetPoint1(self._p1)
     self._plane.SetPoint2(self._p2)
     self._plane.Update()
     self.normalizePlaneSize()
     self.createBoundsPlanes()
     self._resliceTransform = None
Ejemplo n.º 16
0
 def Plane(self):
     p = vtkPlaneSource()
     # Default is:
     # Centre = 0,0,0
     # Normal = 0,0,1
     # Origin = -0.5, -0.5, 0
     # So set the radius first while it's simple
     p.SetOrigin(-self.Radius, -self.Radius, 0.)
     p.SetPoint1(+self.Radius, -self.Radius, 0.)
     p.SetPoint2(-self.Radius, +self.Radius, 0.)
     # Shift to the right place
     p.SetCenter(self.Centre.x, self.Centre.y, self.Centre.z)
     # Orient correctly
     p.SetNormal(self.Normal.x, self.Normal.y, self.Normal.z)
     
     return p
Ejemplo n.º 17
0
    def init_fiducial_actor(self, fiducial_obj):
        """Initialize a plane VTK actor to display the fiducials."""
        plane_source = vtk.vtkPlaneSource()
        plane_source.SetCenter(0.0, 0.0, 0.0)
        plane_source.SetNormal(0.0, 0.0, 1.0)
        plane_source.Update()
        plane = plane_source.GetOutput()
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputData(plane)

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetColor(1.0, 0.0, 0.0)
        actor.SetScale(fiducial_obj.apriltag_properties.dimensions.x,
                       fiducial_obj.apriltag_properties.dimensions.y, 1.0)
        return actor
Ejemplo n.º 18
0
    def planesCallback(self, obj, event):

        fp = self.ren_list[1].GetActiveCamera().GetFocalPoint()
        p = self.ren_list[1].GetActiveCamera().GetPosition()
        dist = np.sqrt((p[0] - fp[0]) ** 2 + (p[1] - fp[1]) ** 2 + (p[2] - fp[2]) ** 2)
        self.ren_list[1].GetActiveCamera().SetPosition(fp[0], fp[1], fp[2] + dist)
        self.ren_list[1].GetActiveCamera().SetViewUp(0.0, 1.0, 0.0)

        fp = self.ren_list[2].GetActiveCamera().GetFocalPoint()
        p = self.ren_list[2].GetActiveCamera().GetPosition()
        dist = np.sqrt((p[0] - fp[0]) ** 2 + (p[1] - fp[1]) ** 2 + (p[2] - fp[2]) ** 2)
        self.ren_list[2].GetActiveCamera().SetPosition(fp[0] + dist, fp[1], fp[2])
        self.ren_list[2].GetActiveCamera().SetViewUp(0.0, -1.0, 0.0)
        self.ren_list[2].GetActiveCamera().Roll(90)

        fp = self.ren_list[3].GetActiveCamera().GetFocalPoint()
        p = self.ren_list[3].GetActiveCamera().GetPosition()
        dist = np.sqrt((p[0] - fp[0]) ** 2 + (p[1] - fp[1]) ** 2 + (p[2] - fp[2]) ** 2)
        self.ren_list[3].GetActiveCamera().SetPosition(fp[0], fp[1] - dist, fp[2])
        self.ren_list[3].GetActiveCamera().SetViewUp(-1.0, 0.0, 0.0)
        self.ren_list[3].GetActiveCamera().Roll(90)

        new_center = obj.GetCenter()
        new_normal = obj.GetNormal()
        index = obj.index

        new_source = vtk.vtkPlaneSource()
        new_source.SetCenter(new_center)
        new_source.SetNormal(new_normal)
        new_source.Update()

        self.geo_data.foliation_modify(index, X=new_center[0], Y=new_center[1], Z=new_center[2],
                                       G_x=new_normal[0], G_y=new_normal[1], G_z=new_normal[2])
        render = obj.n_render

        if render != 0:
            self.f_rend_1[obj.n_plane].SetInputData(new_source.GetOutput())
            self.f_rend_1[obj.n_plane].SetNormal(new_normal)
        if render != 1:
            self.f_rend_2[obj.n_plane].SetInputData(new_source.GetOutput())
            self.f_rend_2[obj.n_plane].SetNormal(new_normal)
        if render != 2:
            self.f_rend_3[obj.n_plane].SetInputData(new_source.GetOutput())
            self.f_rend_3[obj.n_plane].SetNormal(new_normal)
        if render != 3:
            self.f_rend_4[obj.n_plane].SetInputData(new_source.GetOutput())
            self.f_rend_4[obj.n_plane].SetNormal(new_normal)
Ejemplo n.º 19
0
def Plane(center=(0, 0, 0),
          direction=(0, 0, 1),
          i_size=1,
          j_size=1,
          i_resolution=10,
          j_resolution=10):
    """
    Create a plane

    Parameters
    ----------
    center : list or np.ndarray
        Location of the centroid in [x, y, z]

    direction : list or np.ndarray
        Direction cylinder points to  in [x, y, z]

    i_size : float
        Size of the plane in the i direction.

    j_size : float
        Size of the plane in the i direction.

    i_resolution : int
        Number of points on the plane in the i direction.

    j_resolution : int
        Number of points on the plane in the j direction.

    Returns
    -------
    plane : pyvista.PolyData
        Plane mesh

    """
    planeSource = vtk.vtkPlaneSource()
    planeSource.SetXResolution(i_resolution)
    planeSource.SetYResolution(j_resolution)
    planeSource.Update()

    surf = pyvista.PolyData(planeSource.GetOutput())

    surf.points[:, 0] *= i_size
    surf.points[:, 1] *= j_size
    surf.rotate_y(-90)
    translate(surf, center, direction)
    return surf
Ejemplo n.º 20
0
def floor():
    plane = vtk.vtkPlaneSource()
    reader = vtk.vtkJPEGReader()
    reader.SetFileName(
        pkg_resources.resource_filename(
            __name__, '/'.join(('media', 'imgs', 'floor.jpg'))))
    texture = vtk.vtkTexture()
    texture.SetInputConnection(reader.GetOutputPort())
    map_to_plane = vtk.vtkTextureMapToPlane()
    map_to_plane.SetInputConnection(plane.GetOutputPort())
    mapper = vtk.vtkPolyDataMapper()

    mapper.SetInputConnection(map_to_plane.GetOutputPort())
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.SetTexture(texture)
    return actor
Ejemplo n.º 21
0
def makeBorderPD(ipw):

    # setup source
    ps = vtk.vtkPlaneSource()
    ps.SetOrigin(ipw.GetOrigin())
    ps.SetPoint1(ipw.GetPoint1())
    ps.SetPoint2(ipw.GetPoint2())

    fe = vtk.vtkFeatureEdges()
    fe.SetInput(ps.GetOutput())

    tubef = vtk.vtkTubeFilter()
    tubef.SetNumberOfSides(12)
    tubef.SetRadius(0.5)
    tubef.SetInput(fe.GetOutput())

    return tubef.GetOutput()
    def CreateImageLabelModel(self, width, height):
        # Create Image Label Transform if not in scene already
        try:
            self.imageLabelTransform = slicer.util.getNode(
                "ImageLabelTransform")
        except:
            self.imageLabelTransform = slicer.util.loadTransform(
                os.path.join(self.resourcePath,
                             'Resources/ImageLabelTransform.h5'))
            self.imageLabelTransform.SetAndObserveTransformNodeID(
                self.sceneTransform.GetID())
            # Create Backup so we can move red border back to there
            self.imageLabelMatrix = vtk.vtkMatrix4x4()
            self.imageLabelTransform.GetMatrixTransformToParent(
                self.imageLabelMatrix)
            self.imageLabelTransformBackup = self.imageLabelTransform

        # Create Instruction Model Node if not in scene already
        try:
            self.imageLabelModelNode = slicer.util.getNode("ImageLabelModel")
        except:
            self.imageLabelPlane = vtk.vtkPlaneSource()
            self.imageLabelPlane.SetPoint1(0, height, 0)
            self.imageLabelPlane.SetPoint2(width, 0, 0)
            self.imageLabelPlane.SetOrigin(0, 0, 0)
            self.imageLabelPlane.Update()
            self.pngImageReader = vtk.vtkPNGReader()
            self.pngImageReader.SetFileName(
                os.path.join(self.resourcePath,
                             'Resources/RedBorderTrans.png'))
            self.pngImageReader.Update()
            self.imageLabelModelNode = slicer.mrmlScene.AddNewNodeByClass(
                'vtkMRMLModelNode')
            self.imageLabelModelNode.SetName("ImageLabelModel")
            self.imageLabelModelNode.CreateDefaultDisplayNodes()
            self.imageLabelModelNode.SetAndObservePolyData(
                self.imageLabelPlane.GetOutput())
            self.imageLabelModelNode.SetAndObserveTransformNodeID(
                self.imageLabelTransform.GetID())
            self.imageLabelModelDisplay = self.imageLabelModelNode.GetDisplayNode(
            )
            self.imageLabelModelDisplay.SetTextureImageDataConnection(
                self.pngImageReader.GetOutputPort())
            self.imageLabelModelDisplay.VisibilityOn()
            self.imageLabelModelDisplay.SetFrontfaceCulling(False)
            self.imageLabelModelDisplay.SetBackfaceCulling(False)
Ejemplo n.º 23
0
def __add_plane_to_ren(center, normal, length, ren):
    import vtk

    center = np.array(center)
    source = vtk.vtkPlaneSource()
    source.SetOrigin(0, 0, 0)
    source.SetPoint1(length, 0, 0)
    source.SetPoint2(0, length, 0)
    source.SetCenter(*center)
    source.SetNormal(*normal)
    source.Update()
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(source.GetOutputPort())
    ac = vtk.vtkActor()
    ac.SetMapper(mapper)
    ren.AddActor(ac)
    return ac
Ejemplo n.º 24
0
def make_vtk_plane():
    ''' Create a plane in vtk and return the actor for the plane.'''

    # create source
    source = vtk.vtkPlaneSource()
    source.SetPoint1(-10, 10, 0)
    source.SetPoint2(10, -10, 0)
    source.SetOrigin(-10, -10, 0)
    # mapper
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(source.GetOutputPort())

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

    return actor
Ejemplo n.º 25
0
def makeBorderPD(ipw):

    # setup source
    ps = vtk.vtkPlaneSource()
    ps.SetOrigin(ipw.GetOrigin())
    ps.SetPoint1(ipw.GetPoint1())
    ps.SetPoint2(ipw.GetPoint2())

    fe = vtk.vtkFeatureEdges()
    fe.SetInput(ps.GetOutput())

    tubef = vtk.vtkTubeFilter()
    tubef.SetNumberOfSides(12)
    tubef.SetRadius(0.5)
    tubef.SetInput(fe.GetOutput())

    return tubef.GetOutput()
Ejemplo n.º 26
0
def grid(pos=[0, 0, 0],
         normal=[0, 0, 1],
         sx=1,
         sy=1,
         c='g',
         bc='darkgreen',
         lw=1,
         alpha=1,
         legend=None,
         resx=10,
         resy=10):
    '''Return a grid plane.

    .. hint:: Example: `brownian2D.py <https://github.com/marcomusy/vtkplotter/blob/master/examples/advanced/brownian2D.py>`_

        .. image:: https://user-images.githubusercontent.com/32848391/50738948-73ce8300-11d9-11e9-8ef6-fc4f64c4a9ce.gif
    '''
    ps = vtk.vtkPlaneSource()
    ps.SetResolution(resx, resy)
    ps.Update()
    poly0 = ps.GetOutput()
    t0 = vtk.vtkTransform()
    t0.Scale(sx, sy, 1)
    tf0 = vtk.vtkTransformPolyDataFilter()
    tf0.SetInputData(poly0)
    tf0.SetTransform(t0)
    tf0.Update()
    poly = tf0.GetOutput()
    axis = np.array(normal) / np.linalg.norm(normal)
    theta = np.arccos(axis[2])
    phi = np.arctan2(axis[1], axis[0])
    t = vtk.vtkTransform()
    t.PostMultiply()
    t.RotateY(theta * 57.3)
    t.RotateZ(phi * 57.3)
    tf = vtk.vtkTransformPolyDataFilter()
    tf.SetInputData(poly)
    tf.SetTransform(t)
    tf.Update()
    pd = tf.GetOutput()
    actor = Actor(pd, c=c, bc=bc, alpha=alpha, legend=legend)
    actor.GetProperty().SetRepresentationToWireframe()
    actor.GetProperty().SetLineWidth(lw)
    actor.SetPosition(pos)
    actor.PickableOff()
    return actor
Ejemplo n.º 27
0
def Grid(
    pos=(0, 0, 0),
    normal=(0, 0, 1),
    sx=1,
    sy=1,
    c="g",
    bc="darkgreen",
    lw=1,
    alpha=1,
    resx=10,
    resy=10,
):
    """Return a grid plane.

    .. hint:: |brownian2D| |brownian2D.py|_
    """
    ps = vtk.vtkPlaneSource()
    ps.SetResolution(resx, resy)
    ps.Update()
    poly0 = ps.GetOutput()
    t0 = vtk.vtkTransform()
    t0.Scale(sx, sy, 1)
    tf0 = vtk.vtkTransformPolyDataFilter()
    tf0.SetInputData(poly0)
    tf0.SetTransform(t0)
    tf0.Update()
    poly = tf0.GetOutput()
    axis = np.array(normal) / np.linalg.norm(normal)
    theta = np.arccos(axis[2])
    phi = np.arctan2(axis[1], axis[0])
    t = vtk.vtkTransform()
    t.PostMultiply()
    t.RotateY(np.rad2deg(theta))
    t.RotateZ(np.rad2deg(phi))
    tf = vtk.vtkTransformPolyDataFilter()
    tf.SetInputData(poly)
    tf.SetTransform(t)
    tf.Update()
    pd = tf.GetOutput()
    actor = Actor(pd, c=c, bc=bc, alpha=alpha)
    actor.GetProperty().SetRepresentationToWireframe()
    actor.GetProperty().SetLineWidth(lw)
    actor.SetPosition(pos)
    settings.collectable_actors.append(actor)
    return actor
Ejemplo n.º 28
0
    def __init__(self, parent=None):
        super(VTKFrame, self).__init__(parent)

        self.vtkWidget = QVTKRenderWindowInteractor(self)
        vl = QtGui.QVBoxLayout(self)
        vl.addWidget(self.vtkWidget)
        vl.setContentsMargins(0, 0, 0, 0)

        self.ren = vtk.vtkRenderer()
        self.ren.SetBackground(0.1, 0.2, 0.4)
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()

        # Provide some geometry
        resolution = 8
        aPlane = vtk.vtkPlaneSource()
        aPlane.SetXResolution(resolution)
        aPlane.SetYResolution(resolution)
        aPlane.Update()

        # Create cell data
        cellData = vtk.vtkUnsignedCharArray()
        cellData.SetNumberOfComponents(3)
        cellData.SetNumberOfTuples(aPlane.GetOutput().GetNumberOfCells())

        for i in range(aPlane.GetOutput().GetNumberOfCells()):
            rgb = random.randint(64, 255), random.randint(64,
                                                          255), random.randint(
                                                              64, 255)
            cellData.InsertTuple(i, rgb)

        aPlane.GetOutput().GetCellData().SetScalars(cellData)

        # Create a mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(aPlane.GetOutputPort())

        # Create an actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)

        self.ren.AddActor(actor)
        self.ren.ResetCamera()

        self._initialized = False
Ejemplo n.º 29
0
def make_color_plane(x, y, colors):
    plane = vtk.vtkPlaneSource()
    plane.SetXResolution(x)
    plane.SetYResolution(y)

    plane.Update()
    colorData = colors_to_scalars(colors)

    plane.GetOutput().GetCellData().SetScalars(colorData)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(plane.GetOutputPort())
    mapper.SetScalarModeToUseCellData()
    mapper.Update()

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    return actor
Ejemplo n.º 30
0
def make_color_plane(x, y, colors):
    plane = vtk.vtkPlaneSource()
    plane.SetXResolution(x)
    plane.SetYResolution(y)

    plane.Update()
    colorData = colors_to_scalars(colors)

    plane.GetOutput().GetCellData().SetScalars(colorData)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(plane.GetOutputPort())
    mapper.SetScalarModeToUseCellData()
    mapper.Update()

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    return actor
Ejemplo n.º 31
0
    def addPlane(self,
                 name,
                 point1,
                 point2,
                 point3,
                 color=np.array([255.0, 255.0, 255.0]),
                 opacity=1.0):
        self.removeActorByName(name)

        # Create a plane
        planeSource = vtk.vtkPlaneSource()
        # planeSource.SetOrigin(center_point[0], center_point[1], center_point[2])
        # #planeSource.SetNormal(normal_vector[0], normal_vector[1], normal_vector[2])
        # #print(dir(planeSource))
        # planeSource.SetPoint1(top_left_point[0], top_left_point[1], top_left_point[2])
        # planeSource.SetPoint2(bot_right_point[0], bot_right_point[1], bot_right_point[2])
        # planeSource.SetXResolution(10)
        # planeSource.SetYResolution(340)
        planeSource.SetOrigin(point1[0], point1[1], point1[2])
        planeSource.SetPoint1(point2[0], point2[1], point2[2])
        planeSource.SetPoint2(point3[0], point3[1], point3[2])
        planeSource.SetXResolution(10)
        planeSource.SetYResolution(340)

        planeSource.Update()

        plane = planeSource.GetOutput()

        # Create a mapper and actor
        polygonMapper = vtk.vtkPolyDataMapper()
        if vtk.VTK_MAJOR_VERSION <= 5:
            polygonMapper.SetInputConnection(polygon.GetProducerPort())
        else:
            polygonMapper.SetInputData(plane)
            polygonMapper.Update()

        polygonActor = vtk.vtkActor()
        polygonActor.SetMapper(polygonMapper)
        polygonActor.GetProperty().SetColor([color[0], color[1], color[2]])
        polygonActor.GetProperty().SetOpacity(opacity)
        #actor.GetProperty().SetColor(colors->GetColor3d("Cyan").GetData());

        self.ren.AddActor(polygonActor)
        self.actor_list[name] = polygonActor
Ejemplo n.º 32
0
    def call_back_plane_move_changes(self, indices):
        df_changes = self.model._orientations.df.loc[np.atleast_1d(indices).astype(int)][['X', 'Y', 'Z',
                                                                                          'G_x', 'G_y', 'G_z', 'id']]
        for index, new_values_df in df_changes.iterrows():
            new_center = new_values_df[['X', 'Y', 'Z']].values
            new_normal = new_values_df[['G_x', 'G_y', 'G_z']].values
            new_source = vtk.vtkPlaneSource()
            new_source.SetCenter(new_center)
            new_source.SetNormal(new_normal)
            new_source.Update()

            plane1 = self.orientations_widgets[index]
            #  plane1.SetInputData(new_source.GetOutput())
            plane1.SetNormal(new_normal)
            plane1.SetCenter(new_center[0], new_center[1], new_center[2])

            _color_lot = self._get_color_lot(is_faults=True, is_basement=False, index='id')
            plane1.GetPlaneProperty().SetColor(mcolors.hex2color(_color_lot[int(new_values_df['id'])]))
            plane1.GetHandleProperty().SetColor(mcolors.hex2color(_color_lot[int(new_values_df['id'])]))
Ejemplo n.º 33
0
    def makeZCutter(self, bounds, scaleFactor, value):
        """ create z cutter plane """

        npos = self._calculateZCutterPos(value)
        self.zplane = vtk.vtkPlane()
        self.zplane.SetOrigin(0, 0, npos)
        self.zplane.SetNormal(0, 0, 1)

        self.ZCutter = vtk.vtkCutter()
        self.ZCutter.SetInputConnection(self.warp.GetOutputPort())
        self.ZCutter.SetCutFunction(self.zplane)
        self.ZCutter.GenerateCutScalarsOff()

        self.ZCutterMapper = vtk.vtkPolyDataMapper()
        self.ZCutterMapper.SetInputConnection(self.ZCutter.GetOutputPort())

        # visual plane to move
        plane = vtk.vtkPlaneSource()
        plane.SetResolution(50, 50)
        plane.SetCenter(0, 0, 0)
        plane.SetNormal(0, 0, 1)

        tran = vtk.vtkTransform()
        tran.Translate((bounds[1] - bounds[0]) / 2. - (0 - bounds[0]), (bounds[3] - bounds[2]) / 2. - (0 - bounds[2]),
                       npos)
        tran.Scale((bounds[1] - bounds[0]), (bounds[3] - bounds[2]), 1)
        tran.PostMultiply()

        self.ZCutterTransform = tran

        tranf = vtk.vtkTransformPolyDataFilter()
        tranf.SetInputConnection(plane.GetOutputPort())
        tranf.SetTransform(tran)

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

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetColor(0.9, 0.9, 0.9)
        actor.GetProperty().SetOpacity(self.opacitySlice)

        return actor
def plane(pos=[0, 0, 0],
          normal=[0, 0, 1],
          sx=1,
          sy=None,
          c='g',
          bc='darkgreen',
          alpha=1,
          legend=None,
          texture=None):
    '''
    Draw a plane of size sx and sy oriented perpendicular to vector normal  
    and so that it passes through point pos.
    '''
    if sy is None: sy = sx
    ps = vtk.vtkPlaneSource()
    ps.SetResolution(1, 1)
    tri = vtk.vtkTriangleFilter()
    tri.SetInputConnection(ps.GetOutputPort())
    tri.Update()
    poly = tri.GetOutput()
    axis = np.array(normal) / np.linalg.norm(normal)
    theta = np.arccos(axis[2])
    phi = np.arctan2(axis[1], axis[0])
    t = vtk.vtkTransform()
    t.PostMultiply()
    t.Scale(sx, sy, 1)
    t.RotateY(theta * 57.3)
    t.RotateZ(phi * 57.3)
    tf = vtk.vtkTransformPolyDataFilter()
    vu.setInput(tf, poly)
    tf.SetTransform(t)
    tf.Update()
    pd = tf.GetOutput()
    actor = vu.makeActor(pd,
                         c=c,
                         bc=bc,
                         alpha=alpha,
                         legend=legend,
                         texture=texture)
    actor.SetPosition(pos)
    actor.PickableOff()
    return actor
Ejemplo n.º 35
0
    def make_texture_overly_object(self):
        input_image = self.session.overlay_image_fname
        reader = vtk.vtkJPEGReader()
        reader.SetFileName(input_image)
        texture = vtk.vtkTexture()
        texture.SetInput(reader.GetOutput())
        texture.SetInputConnection(reader.GetOutputPort())
        texture.InterpolateOn()

        plane = vtk.vtkPlaneSource()
        plane.SetOrigin((0, 0, 0))
        plane.SetPoint1(self.bounds.lat_max_distance)
        plane.SetPoint2(self.bounds.long_max_distance)

        planeMapper = vtk.vtkPolyDataMapper()
        planeMapper.SetInputConnection(plane.GetOutputPort())
        self.overlayActor = vtk.vtkActor()
        self.overlayActor.SetMapper(planeMapper)
        self.overlayActor.SetTexture(texture)
        self.actors.append(self.overlayActor)
Ejemplo n.º 36
0
    def add_plane(self, center, normal):
        """Add a plane to the viewer
        
        Parameters
        ----------
        center : array_like
            The origin of the plane
        normal : array_like
            The normal of the plane
        """

        plane = vtk.vtkPlaneSource()
        plane.SetCenter(center)
        plane.SetNormal(normal)

        mapper = vtk.vtkPolyDataMapper()
        if vtk.VTK_MAJOR_VERSION <= 5:
            mapper.SetInput(plane.GetOutput())
        else:
            mapper.SetInputData(plane.GetOutput())
Ejemplo n.º 37
0
Archivo: epdp.py Proyecto: ecell/newio
    def __create_planes(self):
        plane_list = []
        scaling = self.settings.scaling
        for x in self.settings.plane_surface_list:
            actor = vtk.vtkActor()
            plane = vtk.vtkPlaneSource()
            plane.SetOrigin(x["origin"] * scaling)
            plane.SetPoint1(x["axis1"] * scaling)
            plane.SetPoint2(x["axis2"] * scaling)

            mapper = vtk.vtkPolyDataMapper()
            mapper.SetInput(plane.GetOutput())

            actor.SetMapper(mapper)
            prop = actor.GetProperty()
            prop.SetColor(x["color"])
            prop.SetOpacity(x["opacity"])
            plane_list.append(actor)

        return plane_list
Ejemplo n.º 38
0
    def make_texture_overly_object(self):
        input_image = self.session.overlay_image_fname
        reader = vtk.vtkJPEGReader()
        reader.SetFileName(input_image)
        texture = vtk.vtkTexture()
        texture.SetInput(reader.GetOutput())
        texture.SetInputConnection(reader.GetOutputPort())
        texture.InterpolateOn()

        plane = vtk.vtkPlaneSource()
        plane.SetOrigin((0, 0, 0))
        plane.SetPoint1(self.bounds.lat_max_distance)
        plane.SetPoint2(self.bounds.long_max_distance)

        planeMapper = vtk.vtkPolyDataMapper()
        planeMapper.SetInputConnection(plane.GetOutputPort())
        self.overlayActor = vtk.vtkActor()
        self.overlayActor.SetMapper(planeMapper)
        self.overlayActor.SetTexture(texture)
        self.actors.append(self.overlayActor)
Ejemplo n.º 39
0
    def _create_planes(self):
        plane_list = []
        scaling = self.settings.scaling
        for x in self.settings.plane_surface_list:
            actor = vtk.vtkActor()
            plane = vtk.vtkPlaneSource()
            plane.SetOrigin(numpy.array(x['origin']) * scaling)
            plane.SetPoint1(numpy.array(x['axis1']) * scaling)
            plane.SetPoint2(numpy.array(x['axis2']) * scaling)

            mapper = vtk.vtkPolyDataMapper()
            mapper.SetInput(plane.GetOutput())

            actor.SetMapper(mapper)
            prop = actor.GetProperty()
            prop.SetColor(x['color'])
            prop.SetOpacity(x['opacity'])
            plane_list.append(actor)

        return plane_list
Ejemplo n.º 40
0
    def _create_planes(self):
        plane_list = []
        scaling = self.settings.scaling
        for x in self.settings.plane_surface_list:
            actor = vtk.vtkActor()
            plane = vtk.vtkPlaneSource()
            plane.SetOrigin(numpy.array(x['origin']) * scaling)
            plane.SetPoint1(numpy.array(x['axis1']) * scaling)
            plane.SetPoint2(numpy.array(x['axis2']) * scaling)

            mapper = vtk.vtkPolyDataMapper()
            mapper.SetInput(plane.GetOutput())

            actor.SetMapper(mapper)
            prop = actor.GetProperty()
            prop.SetColor(x['color'])
            prop.SetOpacity(x['opacity'])
            plane_list.append(actor)

        return plane_list
Ejemplo n.º 41
0
def create_textured_plane(**kwargs):
    """
    create a plane with correct size and texture it with a map
    """
    image_reader = vtk.vtkPNGReader()
    image_reader.SetFileName(kwargs['map'])

    plane = vtk.vtkPlaneSource()
    size = kwargs['size']
    z_level = 0.0
    plane.SetOrigin(-0.5 * size[0], -0.5 * size[1], z_level)
    plane.SetPoint1(+0.5 * size[0], -0.5 * size[1], z_level)
    plane.SetPoint2(-0.5 * size[0], +0.5 * size[1], z_level)

    texture = vtk.vtkTexture()
    texture.SetInputConnection(image_reader.GetOutputPort())

    texture_plane = vtk.vtkTextureMapToPlane()
    texture_plane.SetInputConnection(plane.GetOutputPort())
    return texture_plane, texture
Ejemplo n.º 42
0
def create_textured_plane(**kwargs):
    """
    create a plane with correct size and texture it with a map
    """
    image_reader = vtk.vtkPNGReader()
    image_reader.SetFileName(kwargs['map'])

    plane = vtk.vtkPlaneSource()
    size = kwargs['size']
    z_level = 0.0
    plane.SetOrigin(-0.5*size[0], -0.5*size[1], z_level)
    plane.SetPoint1(+0.5*size[0], -0.5*size[1], z_level)
    plane.SetPoint2(-0.5*size[0], +0.5*size[1], z_level)

    texture = vtk.vtkTexture()
    texture.SetInputConnection(image_reader.GetOutputPort())

    texture_plane = vtk.vtkTextureMapToPlane()
    texture_plane.SetInputConnection(plane.GetOutputPort())
    return texture_plane, texture
    def CreatePlaneModel(self, width, height):
        # Create Instruction Transform Node if not in scene already
        try:
            self.instructionTransform = slicer.util.getNode(
                "InstructionTransform")
        except:
            self.instructionTransform = slicer.util.loadTransform(
                os.path.join(self.resourcePath,
                             'Resources/InstructionTransform.h5'))
            self.instructionTransform.SetAndObserveTransformNodeID(
                self.sceneTransform.GetID())

        # Create Instruction Model Node if not in scene already
        try:
            self.instructionModelNode = slicer.util.getNode("InstructionModel")
        except:
            self.imagePlane = vtk.vtkPlaneSource()
            self.imagePlane.SetPoint1(0, height, 0)
            self.imagePlane.SetPoint2(width, 0, 0)
            self.imagePlane.SetOrigin(0, 0, 0)
            self.imagePlane.Update()
            self.pngReader = vtk.vtkPNGReader()
            #self.pngReader.SetFileName(os.path.join(self.resourcePath, 'Resources/Instructions2.png'))
            self.pngReader.SetFileName(
                os.path.join(self.resourcePath, 'Resources/ThreeViews3.png'))
            self.pngReader.Update()
            self.instructionModelNode = slicer.mrmlScene.AddNewNodeByClass(
                'vtkMRMLModelNode')
            self.instructionModelNode.SetName("InstructionModel")
            self.instructionModelNode.CreateDefaultDisplayNodes()
            self.instructionModelNode.SetAndObservePolyData(
                self.imagePlane.GetOutput())
            self.instructionModelNode.SetAndObserveTransformNodeID(
                self.instructionTransform.GetID())
            self.instructionModelDisplay = self.instructionModelNode.GetDisplayNode(
            )
            self.instructionModelDisplay.SetTextureImageDataConnection(
                self.pngReader.GetOutputPort())
            self.instructionModelDisplay.VisibilityOn()
            self.instructionModelDisplay.SetFrontfaceCulling(False)
            self.instructionModelDisplay.SetBackfaceCulling(False)
def grid(pos=[0, 0, 0],
         normal=[0, 0, 1],
         sx=1,
         sy=1,
         c='g',
         bc='darkgreen',
         lw=1,
         alpha=1,
         legend=None,
         resx=10,
         resy=10):
    '''Return a grid plane'''
    ps = vtk.vtkPlaneSource()
    ps.SetResolution(resx, resy)
    ps.Update()
    poly0 = ps.GetOutput()
    t0 = vtk.vtkTransform()
    t0.Scale(sx, sy, 1)
    tf0 = vtk.vtkTransformPolyDataFilter()
    vu.setInput(tf0, poly0)
    tf0.SetTransform(t0)
    tf0.Update()
    poly = tf0.GetOutput()
    axis = np.array(normal) / np.linalg.norm(normal)
    theta = np.arccos(axis[2])
    phi = np.arctan2(axis[1], axis[0])
    t = vtk.vtkTransform()
    t.PostMultiply()
    t.RotateY(theta * 57.3)
    t.RotateZ(phi * 57.3)
    tf = vtk.vtkTransformPolyDataFilter()
    vu.setInput(tf, poly)
    tf.SetTransform(t)
    tf.Update()
    pd = tf.GetOutput()
    actor = vu.makeActor(pd, c=c, bc=bc, alpha=alpha, legend=legend)
    actor.GetProperty().SetRepresentationToWireframe()
    actor.GetProperty().SetLineWidth(lw)
    actor.SetPosition(pos)
    actor.PickableOff()
    return actor
Ejemplo n.º 45
0
def create_ground_frame(size=300):
    planeSource = vtk.vtkPlaneSource()
    planeSource.SetXResolution(10)
    planeSource.SetYResolution(10)
    planeSource.SetCenter(0.0, 0.0, 0.0)
    planeSource.SetNormal(0.0, 0.0, 1.0)
    planeSource.Update()

    scaled_plane = scale_object(planeSource, size)

    # Create a mapper and actor
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(scaled_plane.GetOutput())

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().EdgeVisibilityOn()
    actor.GetProperty().LightingOff()
    actor.GetProperty().SetOpacity(0.3)
    actor.GetProperty().SetColor([255, 0, 0])
    return actor
Ejemplo n.º 46
0
def DrawPlan(renderer,color,center,normal,scaleFactor,oldActor=None):   
    # Create a plane
    planeSource = vtk.vtkPlaneSource()
    planeSource.SetCenter(0,0,0)
    planeSource.SetNormal(normal)
    planeSource.Update()
   
    # Scale plane
    scaleTransform=vtk.vtkTransform()
    scaleTransform.Scale((scaleFactor))
    scaleFilter = vtk.vtkTransformPolyDataFilter()
    scaleFilter.SetInputConnection(planeSource.GetOutputPort())
    scaleFilter.SetTransform(scaleTransform)
    scaleFilter.Update()

    # Translate plane
    translation = vtk.vtkTransform()
    translation.Translate(center)
    transformFilter = vtk.vtkTransformPolyDataFilter()
    transformFilter.SetInputConnection(scaleFilter.GetOutputPort())
    transformFilter.SetTransform(translation)
    transformFilter.Update()

    plane = transformFilter.GetOutput()

    # Create a mapper and actor
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(plane)

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    #actor.GetProperty().SetRepresentationToWireframe() #plan unfilled
    actor.GetProperty().SetColor(color)
    actor.GetProperty().SetOpacity(0.5)

    if oldActor != None :
        renderer.RemoveActor(oldActor)
    renderer.AddActor(actor)

    return actor
Ejemplo n.º 47
0
 def __init__(self, renderer, parent, screenDistance, width, height, isActiveCamera = False):
     '''
     Initialize the CameraScreen model.
     If you are going to stream data to it, set isActiveCamera to true in the constructor parameters and pass jpeg data to the update method.
     '''
     # Call the parent constructor
     super(CameraScreen,self).__init__(renderer, parent)
     
     # Create a plane for the camera 
     # Ref: http://www.vtk.org/doc/nightly/html/classvtkPlaneSource.html
     planeSource = vtk.vtkPlaneSource()
     # Defaults work for this, so just push it out a bit
     #planeSource.Push(screenDistance)
     
     # Transform scale it to the right size
     trans = vtk.vtkTransform()
     trans.Scale(width, height, 1)
     trans.Translate(0, 0, screenDistance)
     trans.RotateY(180) # Effectively flipping the UV (texture) mapping so that the video isn't left/right flipped
     transF = vtk.vtkTransformPolyDataFilter()
     transF.SetInputConnection(planeSource.GetOutputPort())
     transF.SetTransform(trans)
     
     # Create a test picture and assign it to the screen for now...
     # Ref: http://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/Rendering/Python/TPlane.py
     if not isActiveCamera:
         self.__textReader = vtk.vtkPNGReader()
         self.__textReader.SetFileName("../scene/media/semisortedcameralogo.png")
     else:
         self.__textReader = vtk.vtkJPEGReader()
     self.cameraVtkTexture = vtk.vtkTexture()
     self.cameraVtkTexture.SetInputConnection(self.__textReader.GetOutputPort())
     self.cameraVtkTexture.InterpolateOn()        
     
     # Finally assign the mapper and the actor
     planeMapper = vtk.vtkPolyDataMapper()
     planeMapper.SetInputConnection(transF.GetOutputPort())
      
     self.vtkActor.SetMapper(planeMapper)
     self.vtkActor.SetTexture(self.cameraVtkTexture)
Ejemplo n.º 48
0
    def TextureMappedPlane(self, obj, event):

        # use dummy image data here
        e = vtk.vtkImageEllipsoidSource()

        scene = slicer.mrmlScene

        # Create model node
        model = slicer.vtkMRMLModelNode()
        model.SetScene(scene)
        model.SetName(scene.GenerateUniqueName("2DImageModel"))

        planeSource = vtk.vtkPlaneSource()
        model.SetAndObservePolyData(planeSource.GetOutput())

        # Create display node
        modelDisplay = slicer.vtkMRMLModelDisplayNode()
        modelDisplay.SetColor(1, 1, 0)  # yellow
        # modelDisplay.SetBackfaceCulling(0)
        modelDisplay.SetScene(scene)
        scene.AddNode(modelDisplay)
        model.SetAndObserveDisplayNodeID(modelDisplay.GetID())

        modelDisplay.SetSliceIntersectionVisibility(True)
        modelDisplay.SetVisibility(True)

        # Add to scene
        modelDisplay.SetTextureImageDataConnection(e.GetOutputPort())
        # modelDisplay.SetInputPolyDataConnection(model.GetPolyDataConnection())
        scene.AddNode(model)

        transform = slicer.vtkMRMLLinearTransformNode()
        scene.AddNode(transform)
        model.SetAndObserveTransformNodeID(transform.GetID())

        vTransform = vtk.vtkTransform()
        vTransform.Scale(50, 50, 50)
        vTransform.RotateX(30)
        # transform.SetAndObserveMatrixTransformToParent(vTransform.GetMatrix())
        transform.SetMatrixTransformToParent(vTransform.GetMatrix())
Ejemplo n.º 49
0
    def _createOrthoPipelineForNewIPW(self, ipw):
        """This will create and append all the necessary constructs for a
        single new layer (ipw) to the self._orthoPipeline.

        Make sure you only call this method if the orthoView exists!
        After having done this, you still need to call _syncOrthoView() or
        _resetOrthoView() if you've added a new primary.
        """

        _ps = vtk.vtkPlaneSource()
        _pa = vtk.vtkActor()
        _tm2p = vtk.vtkTextureMapToPlane()
        self._orthoPipeline.append({
            'planeSource': _ps,
            'planeActor': _pa,
            'textureMapToPlane': _tm2p
        })

        _tm2p.AutomaticPlaneGenerationOff()
        _tm2p.SetInput(_ps.GetOutput())
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInput(_tm2p.GetOutput())
        _pa.SetMapper(mapper)

        otherTexture = ipw.GetTexture()

        # we don't just use the texture, else VTK goes mad re-uploading
        # the same texture unnecessarily... let's just make use of the
        # same input, we get much more effective use of the
        # host->GPU bus
        texture = vtk.vtkTexture()
        texture.SetInterpolate(otherTexture.GetInterpolate())
        texture.SetQuality(otherTexture.GetQuality())
        texture.MapColorScalarsThroughLookupTableOff()
        texture.RepeatOff()
        texture.SetInput(otherTexture.GetInput())

        _pa.SetTexture(texture)

        self._renderer.AddActor(_pa)
Ejemplo n.º 50
0
 def Create(self):
     self.plane_widget = plane_widget = vtk.vtkImagePlaneWidget()
     plane_widget.SetInputData(self.img)
     plane_widget.SetPlaneOrientationToXAxes()
     #plane_widget.SetResliceInterpolateToLinear()
     plane_widget.TextureVisibilityOff()
     #Set left mouse button to move and rotate plane
     plane_widget.SetLeftButtonAction(1)
     #SetColor margin to green
     margin_property = plane_widget.GetMarginProperty()
     margin_property.SetColor(0, 0.8, 0)
     #Disable cross
     cursor_property = plane_widget.GetCursorProperty()
     cursor_property.SetOpacity(0)
     self.plane_source = plane_source = vtk.vtkPlaneSource()
     plane_source.SetOrigin(plane_widget.GetOrigin())
     plane_source.SetPoint1(plane_widget.GetPoint1())
     plane_source.SetPoint2(plane_widget.GetPoint2())
     plane_source.SetNormal(plane_widget.GetNormal())
     plane_mapper = self.plane_mapper = vtk.vtkPolyDataMapper()
     plane_mapper.SetInputData(plane_source.GetOutput())
     self.plane_actor = plane_actor = vtk.vtkActor()
     plane_actor.SetMapper(plane_mapper)
     plane_actor.GetProperty().BackfaceCullingOn()
     plane_actor.GetProperty().SetOpacity(0)
     plane_widget.AddObserver("InteractionEvent", self.Update)
     Publisher.sendMessage('AppendActor', actor=self.plane_actor)
     Publisher.sendMessage('Set Widget Interactor',
                           widget=self.plane_widget)
     plane_actor.SetVisibility(1)
     plane_widget.On()
     self.plane = plane = vtk.vtkPlane()
     plane.SetNormal(self.plane_source.GetNormal())
     plane.SetOrigin(self.plane_source.GetOrigin())
     self.volume_mapper.AddClippingPlane(plane)
     #Storage First Position
     self.origin = plane_widget.GetOrigin()
     self.p1 = plane_widget.GetPoint1()
     self.p2 = plane_widget.GetPoint2()
     self.normal = plane_widget.GetNormal()
Ejemplo n.º 51
0
    def _createOrthoPipelineForNewIPW(self, ipw):
        """This will create and append all the necessary constructs for a
        single new layer (ipw) to the self._orthoPipeline.

        Make sure you only call this method if the orthoView exists!
        After having done this, you still need to call _syncOrthoView() or
        _resetOrthoView() if you've added a new primary.
        """

        _ps = vtk.vtkPlaneSource()
        _pa = vtk.vtkActor()
        _tm2p = vtk.vtkTextureMapToPlane()
        self._orthoPipeline.append(
            {'planeSource' : _ps,
             'planeActor' : _pa,
             'textureMapToPlane': _tm2p})

        _tm2p.AutomaticPlaneGenerationOff()
        _tm2p.SetInput(_ps.GetOutput())
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInput(_tm2p.GetOutput())
        _pa.SetMapper(mapper)

        otherTexture = ipw.GetTexture()

        # we don't just use the texture, else VTK goes mad re-uploading
        # the same texture unnecessarily... let's just make use of the
        # same input, we get much more effective use of the
        # host->GPU bus
        texture = vtk.vtkTexture()
        texture.SetInterpolate(otherTexture.GetInterpolate())
        texture.SetQuality(otherTexture.GetQuality())
        texture.MapColorScalarsThroughLookupTableOff()
        texture.RepeatOff()
        texture.SetInput(otherTexture.GetInput())

        _pa.SetTexture(texture)

        self._renderer.AddActor(_pa)
Ejemplo n.º 52
0
def Plane(pos=(0, 0, 0),
          normal=(0, 0, 1),
          sx=1,
          sy=None,
          c="g",
          bc="darkgreen",
          alpha=1,
          texture=None):
    """
    Draw a plane of size `sx` and `sy` oriented perpendicular to vector `normal`
    and so that it passes through point `pos`.

    |Plane|
    """
    if sy is None:
        sy = sx
    ps = vtk.vtkPlaneSource()
    ps.SetResolution(1, 1)
    tri = vtk.vtkTriangleFilter()
    tri.SetInputConnection(ps.GetOutputPort())
    tri.Update()
    poly = tri.GetOutput()
    axis = np.array(normal) / np.linalg.norm(normal)
    theta = np.arccos(axis[2])
    phi = np.arctan2(axis[1], axis[0])
    t = vtk.vtkTransform()
    t.PostMultiply()
    t.Scale(sx, sy, 1)
    t.RotateY(np.rad2deg(theta))
    t.RotateZ(np.rad2deg(phi))
    tf = vtk.vtkTransformPolyDataFilter()
    tf.SetInputData(poly)
    tf.SetTransform(t)
    tf.Update()
    pd = tf.GetOutput()
    actor = Actor(pd, c=c, bc=bc, alpha=alpha, texture=texture)
    actor.SetPosition(pos)
    settings.collectable_actors.append(actor)
    return actor
Ejemplo n.º 53
0
    def create_plane(self, props, texture):
        """Create flat plane"""

        # Pull and scale dimensions
        SIZE = np.asarray(props["Size"])
        POS = np.asarray(props["Translate"])

        # Create texture reader
        reader = vtk.vtkJPEGReader()
        reader.SetFileName(texture)

        # Create texture object
        texture = vtk.vtkTexture()
        texture.SetInputConnection(reader.GetOutputPort())
        texture.InterpolateOn()

        # Create plane model
        plane = vtk.vtkPlaneSource()
        plane.SetResolution(1, 1)
        plane.SetPoint1(0, SIZE[1], 0)
        plane.SetPoint2(SIZE[0], 0, 0)

        # Translate to centre
        transP = vtk.vtkTransform()
        transP.Translate(POS[0], POS[1], POS[2])
        tpd = vtk.vtkTransformPolyDataFilter()
        tpd.SetInputConnection(plane.GetOutputPort())
        tpd.SetTransform(transP)
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(tpd.GetOutputPort())
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.SetTexture(texture)
        actor.GetProperty().SetAmbient(1.0)
        actor.GetProperty().SetSpecular(.5)
        actor.GetProperty().SetSpecularPower(5.0)
        actor.GetProperty().SetDiffuse(0.2)

        return actor
Ejemplo n.º 54
0
 def Create(self):
     self.plane_widget = plane_widget = vtk.vtkImagePlaneWidget()
     plane_widget.SetInputData(self.img)
     plane_widget.SetPlaneOrientationToXAxes()
     #plane_widget.SetResliceInterpolateToLinear()
     plane_widget.TextureVisibilityOff()
     #Set left mouse button to move and rotate plane
     plane_widget.SetLeftButtonAction(1)
     #SetColor margin to green
     margin_property = plane_widget.GetMarginProperty()
     margin_property.SetColor(0,0.8,0)
     #Disable cross
     cursor_property = plane_widget.GetCursorProperty()
     cursor_property.SetOpacity(0) 
     self.plane_source = plane_source = vtk.vtkPlaneSource()
     plane_source.SetOrigin(plane_widget.GetOrigin())
     plane_source.SetPoint1(plane_widget.GetPoint1())
     plane_source.SetPoint2(plane_widget.GetPoint2())
     plane_source.SetNormal(plane_widget.GetNormal())
     plane_mapper = self.plane_mapper = vtk.vtkPolyDataMapper()
     plane_mapper.SetInputData(plane_source.GetOutput())
     self.plane_actor = plane_actor = vtk.vtkActor()
     plane_actor.SetMapper(plane_mapper)
     plane_actor.GetProperty().BackfaceCullingOn()
     plane_actor.GetProperty().SetOpacity(0)
     plane_widget.AddObserver("InteractionEvent", self.Update)
     Publisher.sendMessage('AppendActor', self.plane_actor)
     Publisher.sendMessage('Set Widget Interactor', self.plane_widget)
     plane_actor.SetVisibility(1)
     plane_widget.On() 
     self.plane = plane = vtk.vtkPlane()
     plane.SetNormal(self.plane_source.GetNormal())
     plane.SetOrigin(self.plane_source.GetOrigin())
     self.volume_mapper.AddClippingPlane(plane) 
     #Storage First Position
     self.origin = plane_widget.GetOrigin()
     self.p1 = plane_widget.GetPoint1()
     self.p2 = plane_widget.GetPoint2()
     self.normal = plane_widget.GetNormal()
Ejemplo n.º 55
0
    def CreateGround(self, size=4000):
        # create plane source
        plane = vtk.vtkPlaneSource()
        plane.SetXResolution(100)
        plane.SetYResolution(100)
        plane.SetCenter(0.3, 0.3, 0)
        plane.SetNormal(0, 0, 1)

        # mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(plane.GetOutputPort())

        # actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetRepresentationToWireframe()
        actor.GetProperty().SetColor(211 / 255, 211 / 255, 211 / 255)
        transform = vtk.vtkTransform()
        transform.Scale(size, size, 1)
        actor.SetUserTransform(transform)

        return actor
Ejemplo n.º 56
0
def main():
    colors = vtk.vtkNamedColors()

    # Set the background color.
    colors.SetColor('BkgColor', [26, 51, 77, 255])

    # Create a plane
    planeSource = vtk.vtkPlaneSource()
    planeSource.SetCenter(1.0, 0.0, 0.0)
    planeSource.SetNormal(1.0, 0.0, 1.0)
    planeSource.Update()

    plane = planeSource.GetOutput()

    # Create a mapper and actor
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(plane)

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(colors.GetColor3d('Banana'))

    # Create a renderer, render window and interactor
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.SetWindowName('Plane')
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

    # Add the actors to the scene
    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d('BkgColor'))

    # Render and interact
    renderWindow.Render()
    renderWindowInteractor.Start()
Ejemplo n.º 57
0
def main(vector_file, magnitude_file):

    num_critical_points = 6
    CriticalPoints = vtk.vtkPoints()

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

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

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

    mags = reader.GetOutput()

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

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

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

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

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

        plane1.append(vtk.vtkPlaneSource())

    integ = vtk.vtkRungeKutta4()

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

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

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

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

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

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

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

    renderer = vtk.vtkRenderer()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    renderer.AddActor(bar)

    renderer.AddActor(outlineActor)

    renderer_window.Render()
    interactor.Start()
 def init_planes(self):
     self.vtkPlanes = vtk.vtkPlaneSource()
     plane_mapper = vtk.vtkPolyDataMapper()
     plane_mapper.SetInput(self.vtkPlanes.GetOutput())
     self.plane_vtkActor = vtk.vtkActor()
     self.plane_vtkActor.SetMapper(plane_mapper)
Ejemplo n.º 59
0
import vtk

# create a rendering window and renderer
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)

# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# create source
source = vtk.vtkPlaneSource()
source.SetCenter(1,0,0)
source.SetNormal(1,2,3)

# mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(source.GetOutput())

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

# assign actor to the renderer
ren.AddActor(actor)

# enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()