Esempio n. 1
0
    def __init__(self, dataShape, interactor):
        self.dataShape = dataShape
        self.planes = []
        self.coordinate = [0,0,0]
        self.lastChangedAxis = -1
        for i in range(3):
            p = vtkImplicitPlaneRepresentation()
            p.SetPlaceFactor(1.0)
            p.OutsideBoundsOn()
            p.ScaleEnabledOff()
            p.SetOrigin(0.25,0.25,0.25)
            p.PlaceWidget([0.1,dataShape[0],0.1,dataShape[1],0.1,dataShape[2]])

            args = [0, 0, 0]
            args[i] = 1
            p.SetNormal(*args)
            p.GetSelectedPlaneProperty().SetColor(*args)
            p.GetEdgesProperty().SetColor(*args) #bug in VTK

            p.GetPlaneProperty().SetOpacity(0.001)
            #do not draw outline
            p.GetOutlineProperty().SetColor(0,0,0)
            p.GetOutlineProperty().SetOpacity(0.0)
            #do not draw normal
            p.GetSelectedNormalProperty().SetOpacity(0.0)
            p.GetNormalProperty().SetOpacity(0.0)
            p.OutlineTranslationOff()
            p.TubingOff()
            
            self.cross = vtkPolyData()
            points = vtkPoints()
            polys = vtkCellArray()
            points.SetNumberOfPoints(6)
            for i in range(3):
                polys.InsertNextCell(2)
                polys.InsertCellPoint(2*i); polys.InsertCellPoint(2*i+1)
            self.cross.SetPoints(points)
            self.cross.SetLines(polys)
            
            pw = vtkImplicitPlaneWidget2()
            pw.SetRepresentation(p)
            pw.SetInteractor(interactor)
            pw.AddObserver("InteractionEvent", self.__PlanePositionCallback)
            
            self.planes.append(pw)
            
        tubes = vtkTubeFilter()
        tubes.SetNumberOfSides(16)
        tubes.SetInput(self.cross)
        tubes.SetRadius(1.0)
        
        crossMapper = vtkPolyDataMapper()
        crossMapper.SetInput(self.cross)
        crossActor = vtkActor()
        crossActor.SetMapper(crossMapper)
        crossActor.GetProperty().SetColor(0,0,0)
        self.AddPart(crossActor)
        
        #initially invoke the event!
        self.InvokeEvent("CoordinatesEvent")
    def update_model( self, render=True ):
        model = self.pca.mean_.copy()
        for i in range(self.pca.components_.shape[0]):
            model += self.weights[i] * self.pca.components_[i]
        print model
        for i,s in enumerate(self.sources):
            s.SetCenter( model[3*i],
                         model[3*i+1],
                         model[3*i+2] )
            self.poly.GetPoints().SetPoint(i,
                                 model[3*i],
                                  model[3*i+1],
                                  model[3*i+2])

        # get a new tube filter
        self.tubes = vtk.vtkTubeFilter()
        self.tubes.SetInput(self.poly)
        self.tubes.SetRadius(0.1)
        self.tubes.SetNumberOfSides(6)
        self.mappers.append( vtk.vtkPolyDataMapper() )
        self.mappers[0].SetInputConnection(self.tubes.GetOutputPort())
        self.actors[0].SetMapper(self.mappers[0])
        
        if render:
            self.vtkWidget.Render()
        return
Esempio n. 3
0
 def __init__(self, pos, radius, rgb=[0.62, 0, 0.77]):
     self.source = vtk.vtkCubeSource()
     self.mapper = vtk.vtkPolyDataMapper()
     
     # length of sides
     self.source.SetXLength(radius)
     self.source.SetYLength(radius)
     self.source.SetZLength(radius)
     
     # centre
     self.source.SetCenter(pos)
     
     # edges filter
     edges = vtk.vtkExtractEdges()
     edges.SetInputConnection(self.source.GetOutputPort())
     
     # tube filter
     tubes = vtk.vtkTubeFilter()
     tubes.SetInputConnection(edges.GetOutputPort())
     tubes.SetRadius(0.15)
     tubes.SetNumberOfSides(5)
     tubes.UseDefaultNormalOn()
     tubes.SetDefaultNormal(.577, .577, .577)
     
     # mapper
     self.mapper.SetInputConnection(tubes.GetOutputPort())
     
     # actor
     self.SetMapper(self.mapper)
     self.GetProperty().SetColor(rgb)
Esempio n. 4
0
    def __init__(self, centers, vectors, radii, alpha=1, cmap=None):
        tails = centers - np.divide(vectors, 2.)
        heads = centers + np.divide(vectors, 2.)
        points = np.vstack(zip(tails, heads))
        pairs = np.arange(len(centers)*2).reshape(-1, 2)
        radii = np.repeat(radii, 2)

        assert (points.size/3. == pairs.size)
        assert (pairs.size == radii.size)

        self.polydata = vtk.vtkPolyData()
        self.set_points(points)
        self.set_lines(pairs)
        self.set_scalars(radii)

        self.tubeFilter = vtk.vtkTubeFilter()
        self.tubeFilter.SetInput(self.polydata)
        self.tubeFilter.SetVaryRadiusToVaryRadiusByAbsoluteScalar()
        self.tubeFilter.SetNumberOfSides(10)
        # self.tubeFilter.CappingOn()

        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInputConnection(self.tubeFilter.GetOutputPort())
        self.mapper.ScalarVisibilityOff()
        self.SetMapper(self.mapper)

        self.GetProperty().SetOpacity(alpha)

        self.script = [0]
Esempio n. 5
0
    def render(self, pointsData, scalarsArray, radiusArray, nspecies, colouringOptions, atomScaleFactor, lut):
        """
        Render the given antisites (wire frame).
        
        """
        self._logger.debug("Rendering antisites: colour by '%s'", colouringOptions.colourBy)

        # points
        points = vtk.vtkPoints()
        points.SetData(pointsData.getVTK())

        # poly data
        polydata = vtk.vtkPolyData()
        polydata.SetPoints(points)
        polydata.GetPointData().AddArray(scalarsArray.getVTK())
        polydata.GetPointData().SetScalars(radiusArray.getVTK())

        # source
        cubeSource = vtk.vtkCubeSource()
        edges = vtk.vtkExtractEdges()
        edges.SetInputConnection(cubeSource.GetOutputPort())
        glyphSource = vtk.vtkTubeFilter()
        glyphSource.SetInputConnection(edges.GetOutputPort())
        glyphSource.SetRadius(0.05)
        glyphSource.SetVaryRadius(0)
        glyphSource.SetNumberOfSides(5)
        glyphSource.UseDefaultNormalOn()
        glyphSource.SetDefaultNormal(0.577, 0.577, 0.577)

        # glyph
        glyph = vtk.vtkGlyph3D()
        if vtk.vtkVersion.GetVTKMajorVersion() <= 5:
            glyph.SetSource(glyphSource.GetOutput())
            glyph.SetInput(polydata)
        else:
            glyph.SetSourceConnection(glyphSource.GetOutputPort())
            glyph.SetInputData(polydata)
        glyph.SetScaleFactor(atomScaleFactor * 2.0)
        glyph.SetScaleModeToScaleByScalar()
        glyph.ClampingOff()

        # mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(glyph.GetOutputPort())
        mapper.SetLookupTable(lut)
        mapper.SetScalarModeToUsePointFieldData()
        mapper.SelectColorArray("colours")
        utils.setMapperScalarRange(mapper, colouringOptions, nspecies)

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

        # store attributes
        self._actor = utils.ActorObject(actor)
        self._data["Points"] = pointsData
        self._data["Scalars"] = scalarsArray
        self._data["Radius"] = radiusArray
        self._data["LUT"] = lut
        self._data["Scale factor"] = atomScaleFactor
Esempio n. 6
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkTubeFilter(), 'Processing.',
         ('vtkPolyData',), ('vtkPolyData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
    def __init__(self):
        ActorFactory.ActorFactory.__init__(self)

        # Create a green line
        self._Points = vtk.vtkPoints()
        self._Lines = vtk.vtkCellArray()
        self._Poly = vtk.vtkPolyData()

        self._Poly.SetPoints(self._Points)
        self._Poly.SetLines(self._Lines)

        self._PathProperty = vtk.vtkProperty()
        self._PathProperty.SetColor(0, 1, 0)
        self._PathProperty.SetOpacity(0.0)

        # turn the line into a cylinder
        self._tube = vtk.vtkTubeFilter()

        # VTK-6
        if vtk.vtkVersion().GetVTKMajorVersion() > 5:
            self._tube.SetInputData(self._Poly)
        else:
            self._tube.SetInput(self._Poly)

        self._tube.SetNumberOfSides(3)
        self._tube.SetRadius(2.5)
Esempio n. 8
0
    def draw_line(self, l):
        """
        """

        if l in self.lines:
            return
        self.lines.append(l)

        line = vtk.vtkLineSource()
        line.SetPoint1(l.p1.x, l.p1.y, l.p1.z)
        line.SetPoint2(l.p2.x, l.p2.y, l.p2.z)

        # lineMapper = vtk.vtkPolyDataMapper()
        # lineMapper.SetInputConnection(line.GetOutputPort())
        # lineActor = vtk.vtkActor()
        # lineActor.SetMapper(lineMapper)

        tubeFilter = vtk.vtkTubeFilter()
        tubeFilter.SetInputConnection(line.GetOutputPort())
        tubeFilter.SetRadius(l.radius)
        tubeFilter.SetNumberOfSides(10)
        tubeFilter.Update()

        tubeMapper = vtk.vtkPolyDataMapper()
        tubeMapper.SetInputConnection(tubeFilter.GetOutputPort())
        
        tubeActor = vtk.vtkActor()
        tubeActor.SetMapper(tubeMapper)
        tubeActor.GetProperty().SetColor(l.color[0], l.color[1], l.color[2])

        self.rend.AddActor(tubeActor)
        self.tubeActors.append(tubeActor)
Esempio n. 9
0
    def __init__(self, centers, vectors, radii, alpha=1, cmap=None):
        tails = centers - vectors/2.
        heads = centers + vectors/2.
        points = np.vstack(zip(tails, heads))
        pairs = np.arange(len(centers)*2).reshape(-1, 2)
        radii = radii.repeat(2)

        assert (points.size/3. == pairs.size)
        assert (pairs.size == radii.size)

        self.polydata = vtk.vtkPolyData()
        self.polydata.SetPoints(self.pointArray(points))
        self.polydata.SetLines(self.lineArray(pairs))
        self.polydata.GetPointData().SetScalars(self.floatArray(radii))

        self.tubeFilter = vtk.vtkTubeFilter()
        self.tubeFilter.SetInput(self.polydata)
        self.tubeFilter.SetVaryRadiusToVaryRadiusByAbsoluteScalar()
        self.tubeFilter.SetNumberOfSides(10)
        self.tubeFilter.CappingOn()

        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInputConnection(self.tubeFilter.GetOutputPort())
        self.mapper.ScalarVisibilityOff()
        self.SetMapper(self.mapper)

        self.GetProperty().SetOpacity(alpha)
 def _build_scene_tube(self, shape):
     positions = shape.convert_to_positions_sizes()
     joint_count = len(positions)
     pts = vtk.vtkPoints()
     lines = vtk.vtkCellArray()
     lines.InsertNextCell(joint_count)
     for j in range(joint_count):
         pts.InsertPoint(j, positions[j])
         lines.InsertCellPoint(j)
     td = vtk.vtkPolyData()
     td.SetPoints(pts)
     td.SetLines(lines)
     tf = vtk.vtkTubeFilter()
     tf.SetInput(td)
     tf.SetRadius(TUBE_RADIUS)
     # tf.SetVaryRadiusToVaryRadiusOff()
     tf.SetCapping(1)
     tf.SetNumberOfSides(50)
     tf.Update()
     tm = vtk.vtkPolyDataMapper()
     tm.SetInput(tf.GetOutput())
     ta = vtk.vtkActor()
     ta.SetMapper(tm)
     #ta.GetProperty().SetDiffuse(0.8)
     ta.GetProperty().SetAmbient(0.25)
     self.vtkrenderer.AddActor(ta)
Esempio n. 11
0
    def add_bonds(self, neighbors, center):
        """
        Adds bonds for a site.

        Args:
            neighbors:
                Neighbors of the site.
            center:
                The site in the center for all bonds.
        """
        points = vtk.vtkPoints()
        points.InsertPoint(0, center.x, center.y, center.z)
        n = len(neighbors)
        lines = vtk.vtkCellArray()
        for i in range(n):
            points.InsertPoint(i + 1, neighbors[i].coords)
            lines.InsertNextCell(2)
            lines.InsertCellPoint(0)
            lines.InsertCellPoint(i + 1)
        pd = vtk.vtkPolyData()
        pd.SetPoints(points)
        pd.SetLines(lines)

        tube = vtk.vtkTubeFilter()
        tube.SetInput(pd)
        tube.SetRadius(0.1)

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

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        self.ren.AddActor(actor)
Esempio n. 12
0
 def _createCylinder(self, endPt1, endPt2, res=20):
     """
     Create a cylinder oriented to have the given end points.
     
     :@type endPt1: Vec3f
     :@param endPt1: The first end point to align the cylinder with.
     :@type endPt2: Vec3f
     :@param endPt2: The second end point to align the cylinder with.
     :@type radius: float
     :@param radius: The radius of the cylinder.
     :@type res: int
     :@param res: The circular resolution of the cylinder (number of sides). 
                  Must be at least 3.
                  
     :@rtype: vtk.vtkActor
     :@return: A renderable actor representing a cylinder.
     """
     res = 3 if res < 3 else res
     line = vtk.vtkLineSource()
     line.SetPoint1(endPt1.x,endPt1.y,endPt1.z)
     line.SetPoint2(endPt2.x,endPt2.y,endPt2.z)
     # Create a tube filter to represent the line as a cylinder.
     tube = vtk.vtkTubeFilter()
     tube.SetInput(line.GetOutput())
     tube.SetRadius(self.actor_radius)
     tube.SetNumberOfSides(res)
     mapper = vtk.vtkPolyDataMapper()
     mapper.SetInputConnection(tube.GetOutputPort())
     actor = vtk.vtkActor()
     actor.SetMapper(mapper)
     
     return actor    
Esempio n. 13
0
def make_cylinderActor (r, x0, x1, rgb, opacity):
    points = vtk.vtkPoints()
    lines  = vtk.vtkCellArray()
    lines.InsertNextCell(2)
    # point 0
    points.InsertNextPoint(x0[0], x0[1], x0[2])
    lines.InsertCellPoint(0)
    # point 1
    points.InsertNextPoint(x1[0], x1[1], x1[2])
    lines.InsertCellPoint(1)

    cData = vtk.vtkPolyData()
    cData.SetPoints(points)
    cData.SetLines(lines)

    c = vtk.vtkTubeFilter()
    c.SetNumberOfSides(8)
    c.SetInput(cData)
    c.SetRadius(r)

    cMapper = vtk.vtkPolyDataMapper()
    cMapper.SetInput(c.GetOutput())

    cActor = vtk.vtkActor()
    cActor.SetMapper(cMapper)
    cActor.GetProperty().SetColor(rgb[0], rgb[1], rgb[2])
    cActor.GetProperty().SetOpacity(opacity)

    return cActor
Esempio n. 14
0
    def __init__(self, module_manager):
        # initialise our base class
        ModuleBase.__init__(self, module_manager)

        self._tubeFilter = vtk.vtkTubeFilter()
        
        module_utils.setup_vtk_object_progress(self, self._tubeFilter,
                                           'Generating tubes.')
                                           
        self._config.NumberOfSides = 3
        self._config.Radius = 0.01

        configList = [
            ('Number of sides:', 'NumberOfSides', 'base:int', 'text',
             'Number of sides that the tube should have.'),
            ('Tube radius:', 'Radius', 'base:float', 'text',
             'Radius of the generated tube.')]
        ScriptedConfigModuleMixin.__init__(self, configList)        
        
        self._viewFrame = self._createWindow(
            {'Module (self)' : self,
             'vtkTubeFilter' : self._tubeFilter})

        # pass the data down to the underlying logic
        self.config_to_logic()
        # and all the way up from logic -> config -> view to make sure
        self.syncViewWithLogic()
Esempio n. 15
0
 def add_edge(self, start, end, colour=Colours.BASE0):
     """Appends an edge to the edges list."""
     # Line
     line = vtkLineSource()
     line.SetPoint1(start)
     line.SetPoint2(end)
     # Line Mapper
     line_mapper = vtkPolyDataMapper()
     line_mapper.SetInputConnection(line.GetOutputPort())
     self.edge_colours.append(colour)
     self.line_mappers.append(line_mapper)
     # Bar
     bar = vtkTubeFilter()
     bar.SetInputConnection(line.GetOutputPort())
     bar.SetRadius(2.5)
     self.bar_data.append(bar)
     # Bar Mapper
     # Tried this, but mapping the ribbon caused beaucoup errors,
     # debugging would take a week.There must be some kind of way
     # out of here.
     # Said the joker to the thief
     # There's too much confusion
     # I can't get no relief
     # No reason to get excited, the thief he kindly spoke
     # But you and I have been through that
     # And this is not our fate
     # So let us not talk falsely now, the hour is getting late.
     # (2011-08-12)
     bar_mapper = vtkPolyDataMapper()
     bar_mapper.SetInputConnection(bar.GetOutputPort())
     self.bar_mappers.append(bar_mapper)
def CreateAxes():
    global xAxis, yAxis, zAxis, popSplatter

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

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

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

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

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

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

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

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

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

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

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

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

    ZActor = vtk.vtkFollower()
    ZActor.SetMapper(ZTextMapper)
    ZActor.SetScale(0.02, .02, .02)
    ZActor.SetPosition(-0.05, -0.05, 0.35)
    ZActor.GetProperty().SetColor(0, 0, 0)
    return axesActor, XActor, YActor, ZActor
Esempio n. 17
0
 def generate(self):
     if self.actor is not None:
         self.frame.ren.RemoveActor(self.actor)
     self.pts = vtk.vtkPoints()
     self.radii = vtk.vtkFloatArray()
     self.radii.SetName('radii')
     self.colors = vtk.vtkUnsignedCharArray()
     self.colors.SetNumberOfComponents(3)
     self.colors.SetName('colors')
     # nodes
     for k, node in self.K.items():
         self.pts.InsertPoint(k, *node.pos)
         self.radii.InsertTuple1(k, node.radius)
         if self.color_tips_in_yellow and not node.children:
             self.colors.InsertTuple3(k, *name_to_rgb('yellow'))
         else:
             self.colors.InsertTuple3(k, *name_to_rgb(self.base_color))
     # edges
     lines = vtk.vtkCellArray()
     for k, node in self.K.items():
         if node.parent is None: continue
         lines.InsertNextCell(2)
         lines.InsertCellPoint(k)
         lines.InsertCellPoint(node.parent)
     self.polydata = vtk.vtkPolyData()
     self.polydata.SetPoints(self.pts)
     self.polydata.SetLines(lines)
     self.polydata.GetPointData().AddArray(self.radii)
     self.polydata.GetPointData().AddArray(self.colors)
     self.polydata.GetPointData().SetActiveScalars('radii')
     self.tubes = vtk.vtkTubeFilter()
     self.tubes.SetNumberOfSides(10)
     if USING_VTK6:
         self.tubes.SetInputData(self.polydata)
     else:
         self.tubes.SetInput(self.polydata)
     self.tubes.SetVaryRadiusToVaryRadiusByAbsoluteScalar()
     self.tubes.CappingOn()
     self.mapper = vtk.vtkPolyDataMapper()
     if self.show_volume:
         if USING_VTK6:
             self.mapper.SetInputConnection(self.tubes.GetOutputPort())
         else:
             self.mapper.SetInput(self.tubes.GetOutput())
     else:
         if USING_VTK6:
             self.mapper.SetInputData(self.polydata)
         else:
             self.mapper.SetInput(self.polydata)
     self.mapper.ScalarVisibilityOn()
     self.mapper.SetScalarModeToUsePointFieldData()
     self.mapper.SelectColorArray('colors')
     self.actor = vtk.vtkActor()
     self.actor.GetProperty().SetColor(name_to_rgb_float(self.base_color))
     self.actor.SetMapper(self.mapper)
     self.frame.ren.AddActor(self.actor)
     self.frame.ren_win.Render()
Esempio n. 18
0
 def tubeView(self, clipper, pathWidth = 1.2):
     tubes = vtk.vtkTubeFilter()
     tubes.SetInputConnection(clipper.GetOutputPort())
     tubes.SetRadius(pathWidth/2.0)
     tubes.SetNumberOfSides(4)
     tubesMapper = vtk.vtkPolyDataMapper()
     tubesMapper.SetInputConnection(tubes.GetOutputPort())
     tubesActor = vtk.vtkActor()
     tubesActor.SetMapper(tubesMapper)
     return tubesActor
Esempio n. 19
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.2, 0.3, 0.4)
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
 
        # Create Spiral tube
        nV = 256 #No. of vertices
        nCyc = 5 #No. of spiral cycles
        rS = 2.0   #Spiral radius
        h = 10.0
        nTv = 8 #No. of surface elements for each tube vertex

        points = vtk.vtkPoints()
        for i in range(nV):
            vX = rS * math.cos(2 * math.pi * nCyc * i / (nV-1))
            vY = rS * math.sin(2 * math.pi * nCyc * i / (nV-1))
            vZ = h * i / nV
            points.InsertPoint(i, vX, vY, vZ)

        lines = vtk.vtkCellArray()
        lines.InsertNextCell(nV)
        for i in range(nV):
            lines.InsertCellPoint(i)

        polyData = vtk.vtkPolyData()
        polyData.SetPoints(points)
        polyData.SetLines(lines)

        tube = vtk.vtkTubeFilter()
        tube.SetInput(polyData)
        tube.SetNumberOfSides(nTv)
 
        # Create a mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(tube.GetOutputPort())
 
        # Create an actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
 
        self.ren.AddActor(actor)
        self.ren.ResetCamera()

        self._initialized = False
Esempio n. 20
0
 def _createTube(self):
     logging.debug("In MultiSliceContour::createTube()")
     
     points = vtk.vtkPoints()
     for point in self._originalPoints:
         points.InsertNextPoint(point)
                
     self._parametricSpline = vtk.vtkParametricSpline()
     self._parametricSpline.SetPoints(points)
     
     self._parametricFuntionSource = vtk.vtkParametricFunctionSource()
     self._parametricFuntionSource.SetParametricFunction(self._parametricSpline)
     self._parametricFuntionSource.SetUResolution(100)
     
     self._tubeFilter = vtk.vtkTubeFilter()
     self._tubeFilter.SetNumberOfSides(10)
     self._tubeFilter.SetRadius(self._radius)
     self._tubeFilter.SetInputConnection(self._parametricFuntionSource.GetOutputPort())
     
     self._tubeActor = []
     self._cubes = []
     i = 0
     for cutter in self._cutters:
         cutter.SetInputConnection(self._tubeFilter.GetOutputPort())
         cutter.Update()
         
         cube = vtk.vtkBox()
         #TODO change imagebounds to planesourceRange
         cube.SetBounds(self._scene.slice[i].getBounds())
         clip = vtk.vtkClipPolyData()
         clip.SetClipFunction(cube)
         clip.SetInputConnection(cutter.GetOutputPort())
         clip.InsideOutOn()
         clip.Update()          
         self._cubes.append(cube)
         
         tubeMapper=vtk.vtkPolyDataMapper()
         tubeMapper.ScalarVisibilityOff()
         tubeMapper.SetInputConnection(clip.GetOutputPort())
         tubeMapper.GlobalImmediateModeRenderingOn()
         
         tubeActor = vtk.vtkActor()
         tubeActor.SetMapper(tubeMapper)
         tubeActor.GetProperty().LightingOff()
         tubeActor.GetProperty().SetColor(self.lineColor)
         tubeActor.SetUserTransform(self._scene.slice[i].resliceTransform.GetInverse())
         
         
         self._tubeActor.append(tubeActor)
         self._scene.renderer.AddActor(tubeActor)
         i = i+1                
Esempio n. 21
0
    def plot(self):
        """
        plot visualization of data
        """
        self.ren.RemoveAllViewProps()
        # self.marker_widget.EnabledOff()
        active_scalar = self.data.grid[self.current_timestep].GetPointData().GetScalars()
        # print 'active scalar is', active_scalar.GetName()

        line = vtk.vtkLineSource()
        line.SetResolution(30)
        line.SetPoint1(self.line_points[0])
        line.SetPoint2(self.line_points[1])
        probe = vtk.vtkProbeFilter()
        probe.SetInputConnection(line.GetOutputPort())
        probe.SetSourceData(self.data.grid[self.current_timestep])

        tuber = vtk.vtkTubeFilter()
        tuber.SetInputConnection(probe.GetOutputPort())
        tuber.SetRadius(0.02)
        line_mapper = vtk.vtkPolyDataMapper()
        line_mapper.SetInputConnection(tuber.GetOutputPort())
        line_actor = vtk.vtkActor()
        line_actor.SetMapper(line_mapper)
        # self.ren.AddActor(line_actor)

        xyplot = vtk.vtkXYPlotActor()
        if vtk.VTK_MAJOR_VERSION <= 5:
            xyplot.AddInput(probe.GetOutput())
        else:
            xyplot.AddDataSetInputConnection(probe.GetOutputPort())
        xyplot.GetPositionCoordinate().SetValue(0.05, 0.05, 0.0)
        xyplot.GetPosition2Coordinate().SetValue(0.9, 0.9, 0.0) #relative to Position
        xyplot.SetXValuesToArcLength()
        xyplot.SetNumberOfXLabels(6)
        xyplot.SetNumberOfYLabels(6)
        xyplot.SetTitle("title")
        xyplot.SetXTitle("length")
        xyplot.SetYTitle("var")
        # xyplot.SetXRange(.1, .35)
        # xyplot.SetYRange(.2, .4)
        # xyplot.GetProperty().SetColor(0, 0, 0)
        xyplot.GetProperty().SetLineWidth(2)
        self.ren.AddActor2D(xyplot)
        # self.xyplotWidget = vtk.vtkXYPlotWidget()
        # self.xyplotWidget.SetXYPlotActor(xyplot)
        # self.xyplotWidget.SetInteractor(self.iren)
        # self.xyplotWidget.EnabledOn()

        self.ren_win.Render()
Esempio n. 22
0
 def __init__(self, mesh):
     self.cutter = vtkCutter()
     self.cutter.SetCutFunction(vtkPlane())
     self.tubes = vtkTubeFilter()
     self.tubes.SetInputConnection(self.cutter.GetOutputPort())
     self.tubes.SetRadius(1)
     self.tubes.SetNumberOfSides(8)
     self.tubes.CappingOn()
     self.mapper = vtkPolyDataMapper()
     self.mapper.SetInputConnection(self.tubes.GetOutputPort())
     self.actor = vtkActor()
     self.actor.SetMapper(self.mapper)
     self.cutter.SetInput(mesh)
     self.AddPart(self.actor)
Esempio n. 23
0
    def ReadPDB(file_name):
        pdb = vtk.vtkPDBReader()
        pdb.SetFileName(file_name)
        pdb.SetHBScale(1.0)
        pdb.SetBScale(1.0)
        pdb.Update()

        sphere = vtk.vtkSphereSource()
        sphere.SetCenter(0, 0, 0)
        sphere.SetRadius(1)

        glyph = vtk.vtkGlyph3D()
        glyph.SetInputConnection(pdb.GetOutputPort())
        glyph.SetSourceConnection(sphere.GetOutputPort())
        glyph.SetOrient(1)
        glyph.SetColorMode(1)
        glyph.SetScaleMode(2)
        glyph.SetScaleFactor(.25)
        glyph.Update()

        tube = vtk.vtkTubeFilter()
        tube.SetInputConnection(pdb.GetOutputPort())
        tube.SetNumberOfSides(6)
        tube.CappingOff()
        tube.SetRadius(0.2)
        tube.SetVaryRadius(0)
        tube.SetRadiusFactor(10)
        tube.Update()

        tubeMesh = vtk.vtkPolyData()
        tubeMesh.ShallowCopy(tube.GetOutput())
        N = tubeMesh.GetNumberOfPoints()

        rgb_colors = tubeMesh.GetPointData().GetArray("rgb_colors")
        if rgb_colors is not None:
            if rgb_colors.GetNumberOfComponents() == 3:
                for i in range(N):
                    rgb_colors.SetTupleValue(i, (127, 127, 127))

        appendFilter = vtk.vtkAppendPolyData()
        appendFilter.AddInputConnection(glyph.GetOutputPort())
        try:
            appendFilter.AddInputData(tubeMesh)
        except:
            appendFilter.AddInput(tubeMesh)
        appendFilter.Update()

        polyData = vtk.vtkPolyData()
        polyData.ShallowCopy(appendFilter.GetOutput())
        return polyData
Esempio n. 24
0
def make_axesActor():
    axes = vtk.vtkAxes()
    axes.SetOrigin(0,0,0)
    axes.SetScaleFactor(4)
    axesTubes = vtk.vtkTubeFilter()
    axesTubes.SetInput(axes.GetOutput())
    axesTubes.SetRadius(axes.GetScaleFactor()/25.0)
    axesTubes.SetNumberOfSides(6)
    axesMapper = vtk.vtkPolyDataMapper()
    axesMapper.SetInput(axesTubes.GetOutput())
    axesActor = vtk.vtkActor()
    axesActor.SetMapper(axesMapper)
    
    #ren.AddActor(axesActor)
    return (axesActor)
Esempio n. 25
0
 def __init__(self,p1=(0,0,0) , p2=(1,1,1), radius=0.1, color=(0,1,1) ):   
     self.src = vtk.vtkLineSource()
     self.src.SetPoint1(p1)
     self.src.SetPoint2(p2)
     
     self.tubefilter = vtk.vtkTubeFilter()
     self.tubefilter.SetInput( self.src.GetOutput() )
     self.tubefilter.SetRadius( radius )
     self.tubefilter.SetNumberOfSides( 30 )
     self.tubefilter.Update()
     
     self.mapper = vtk.vtkPolyDataMapper()
     self.mapper.SetInputConnection( self.tubefilter.GetOutputPort() )
     self.SetMapper(self.mapper)
     self.SetColor(color)
Esempio n. 26
0
 def showAxis(self):
     if self.axis:
         xmin, xmax, ymin, ymax, zmin, zmax = self.bounds[:]
         axes=vtk.vtkAxes()
         axes.SetOrigin(0.0,0.0,0.0)
         axes.SetScaleFactor(0.1*max([xmax-xmin,ymax-ymin,zmax-zmin]))
         axesTubes=vtk.vtkTubeFilter()
         axesTubes.SetInputConnection(axes.GetOutputPort())
         axesTubes.SetRadius(0.2)
         axesTubes.SetNumberOfSides(6)
         axesMapper=vtk.vtkPolyDataMapper() 
         axesMapper.SetInputConnection(axesTubes.GetOutputPort())
         axesActor=vtk.vtkActor() 
         axesActor.SetMapper(axesMapper)
         XText=vtk.vtkVectorText()    
         XText.SetText("X")
         XTextMapper=vtk.vtkPolyDataMapper() 
         XTextMapper.SetInputConnection(XText.GetOutputPort())
         XActor=vtk.vtkFollower()
         XActor.SetMapper(XTextMapper)
         XActor.SetScale(2.0, 2.0, 2.0)
         XActor.SetPosition(1.11*xmax, ymin, zmin)
         XActor.GetProperty().SetColor(0,0,0)
         XActor.SetCamera(self.cam)
         YText=vtk.vtkVectorText()    
         YText.SetText("Y")
         YTextMapper=vtk.vtkPolyDataMapper() 
         YTextMapper.SetInputConnection(YText.GetOutputPort())
         YActor=vtk.vtkFollower()
         YActor.SetMapper(YTextMapper)
         YActor.SetScale(2.0, 2.0, 2.0)
         YActor.SetPosition(xmin, 1.11*ymax, zmin)
         YActor.GetProperty().SetColor(0,0,0)
         YActor.SetCamera(self.cam)
         ZText=vtk.vtkVectorText()    
         ZText.SetText("Z")
         ZTextMapper=vtk.vtkPolyDataMapper() 
         ZTextMapper.SetInputConnection(ZText.GetOutputPort())
         ZActor=vtk.vtkFollower()
         ZActor.SetMapper(ZTextMapper)
         ZActor.SetScale(2.0, 2.0, 2.0)
         ZActor.SetPosition(xmin, ymin, 1.11*zmax)
         ZActor.GetProperty().SetColor(0,0,0)
         ZActor.SetCamera(self.cam)
         self.ren.AddActor(axesActor)
         self.ren.AddActor(XActor)
         self.ren.AddActor(YActor)
         self.ren.AddActor(ZActor)
Esempio n. 27
0
def tubes(T, P, *args):
    poly_data = vtk.vtkPolyData()
    poly_data.SetPoints(make_vtkPoints(P))
    poly_data.SetLines(make_vtkCellArray(T))

    tube = vtk.vtkTubeFilter()
    _SetInput_or_SetInputData(tube, poly_data)
    _apply_methods(tube, *args)

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

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor._locals = locals()
    return actor
Esempio n. 28
0
    def __init__(self, element, tag=-1):
        super().__init__()
        self.element = element
        self.tag = tag

        self._nodes = vtk.vtkPoints()
        self._edges = vtk.vtkCellArray()
        self._object = vtk.vtkPolyData()

        self.normalizedColor = [0, 1, 1]

        self._tubeFilter = vtk.vtkTubeFilter()
        self._colorFilter = vtk.vtkUnsignedCharArray()
        self._colorFilter.SetNumberOfComponents(3)

        self._mapper = vtk.vtkPolyDataMapper()
Esempio n. 29
0
 def __init__(self):
     self.Center = np.zeros(3)
     self.Height = 1.
     self.Radius = 0.5
     self.Direction = np.array((0., 0., 1.))
     
     # Line down the centre of the tube
     self.Centerline = vtk.vtkPolyData()
     # VTK filter to create a tube
     self.Tuber = vtk.vtkTubeFilter()
     # VTK filter to tidy up the output of Tuber
     self.Triangulator = vtk.vtkTriangleFilter()
     self.Triangulator.SetInputConnection(self.Tuber.GetOutputPort())
     
     self.SetExecuteMethod(self._Execute)
     return
Esempio n. 30
0
    def __init__(self):
        self.Center = np.zeros(3)
        self.Height = 1.
        self.Radius = 0.5
        self.Direction = np.array((0., 0., 1.))

        # Line down the centre of the tube
        self.Centerline = vtk.vtkPolyData()
        # VTK filter to create a tube
        self.Tuber = vtk.vtkTubeFilter()
        # VTK filter to tidy up the output of Tuber
        self.Triangulator = vtk.vtkTriangleFilter()
        self.Triangulator.SetInputConnection(self.Tuber.GetOutputPort())

        self.SetExecuteMethod(self._Execute)
        return
Esempio n. 31
0
def make_bondActor (color):
    bond = vtk.vtkTubeFilter()
    bond.SetNumberOfSides(8)
    # bond.SetInput(bData)
    bond.SetRadius(0.2)

    bondMapper = vtk.vtkPolyDataMapper()
    bondMapper.SetInput(bond.GetOutput())

    bondActor = vtk.vtkActor()
    bondActor.SetMapper(bondMapper)
    bondActor.GetProperty().SetDiffuseColor(khaki)
    bondActor.GetProperty().SetSpecular(.4)
    bondActor.GetProperty().SetSpecularPower(10)

    return (bondActor,bond)
Esempio n. 32
0
 def _create_volume_from_point(node):
     if node.parent is None:
         p = node.coords - node.length * node.axis  # [0, 0, node.length]
     else:
         p = node.parent.coords
     source = vtk.vtkLineSource()
     source.SetPoint1(*p)
     source.SetPoint2(*node.coords)
     tube = vtk.vtkTubeFilter()
     tube.SetRadius(node.radius)
     tube.SetNumberOfSides(50)
     tube.CappingOn()
     tube.SetInputConnection(source.GetOutputPort())
     normal = vtk.vtkPolyDataNormals()
     normal.SetInputConnection(tube.GetOutputPort())
     return tube, normal
Esempio n. 33
0
    def add_bonds(self, neighbors, center, color=None, opacity=None,
                  radius=0.1):
        """
        Adds bonds for a site.

        Args:
            neighbors:
                Neighbors of the site.
            center:
                The site in the center for all bonds.
            color:
                Color of the tubes representing the bonds
            opacity:
                Opacity of the tubes representing the bonds
            radius:
                radius of tube s representing the bonds
        """
        points = vtk.vtkPoints()
        points.InsertPoint(0, center.x, center.y, center.z)
        n = len(neighbors)
        lines = vtk.vtkCellArray()
        for i in range(n):
            points.InsertPoint(i + 1, neighbors[i].coords)
            lines.InsertNextCell(2)
            lines.InsertCellPoint(0)
            lines.InsertCellPoint(i + 1)
        pd = vtk.vtkPolyData()
        pd.SetPoints(points)
        pd.SetLines(lines)

        tube = vtk.vtkTubeFilter()
        if vtk.VTK_MAJOR_VERSION <= 5:
            tube.SetInputConnection(pd.GetProducerPort())
        else:
            tube.SetInputData(pd)
        tube.SetRadius(radius)

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

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        if opacity is not None:
            actor.GetProperty().SetOpacity(opacity)
        if color is not None:
            actor.GetProperty().SetColor(color)
        self.ren.AddActor(actor)
Esempio n. 34
0
 def __init__(self, ren):
     self.ren = ren
     
     # Generate the polyline for the spline.
     self.points = vtk.vtkPoints()
     self.lines = vtk.vtkCellArray()
     self.Data = vtk.vtkPolyData()
     self.Tubes = vtk.vtkTubeFilter()
     self.Tubes.SetInput(self.Data)
     self.Tubes.SetNumberOfSides(8)
     self.Tubes.SetRadius(.1)
     
     self.mapper = vtk.vtkPolyDataMapper()
     self.mapper.SetInput(self.Tubes.GetOutput())
     self.actor = vtk.vtkActor()
     self.actor.SetMapper(self.mapper)
     self.ren.AddActor(self.actor)
Esempio n. 35
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()
Esempio n. 36
0
def _polyLineToTube(pdi, pdo, radius=10.0, numSides=20):
    """
    Takes points from a vtkPolyData with associated poly lines in cell data and builds a polygonal tube around that line with some specified radius and number of sides.
    """
    if pdo is None:
        pdo = vtk.vtkPolyData()
        pdo.DeepCopy(pdi)

    # Make a tube from the PolyData line:
    tube = vtk.vtkTubeFilter()
    tube.SetInputData(pdo)
    tube.SetRadius(radius)
    tube.SetNumberOfSides(numSides)
    tube.Update()
    pdo.ShallowCopy(tube.GetOutput())

    return pdo
Esempio n. 37
0
    def __init__(self, radius=0.0003, number_of_sides=6, **kwargs):
        kwargs["number_of_sides"] = number_of_sides
        kwargs["radius"] = radius

        self.poly_data = vtk.vtkPolyData()

        self.tube_filter = vtk.vtkTubeFilter()
        self.tube_filter.SetInput(self.poly_data)

        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInputConnection(self.tube_filter.GetOutputPort())

        self.actor = vtk.vtkActor()
        self.actor.SetMapper(self.mapper)
        self.actor.GetProperty().BackfaceCullingOn()

        self._process_kwargs(**kwargs)
Esempio n. 38
0
def tubeFromCOMList(COMList, radius, debug=False):
    """
    Input: image-space positions along the tube centreline.
    Output: VTK tube
    Note: positions do not have to be continuous - the tube is interpolated in real space
    """
    points = vtk.vtkPoints()
    for i, pt in enumerate(COMList):
        points.InsertPoint(i, pt[0], pt[1], pt[2])

    # Fit a spline to the points
    if debug:
        print("Fitting spline")
    spline = vtk.vtkParametricSpline()
    spline.SetPoints(points)

    functionSource = vtk.vtkParametricFunctionSource()
    functionSource.SetParametricFunction(spline)
    functionSource.SetUResolution(10 * points.GetNumberOfPoints())
    functionSource.Update()

    # Generate the radius scalars
    tubeRadius = vtk.vtkDoubleArray()
    n = functionSource.GetOutput().GetNumberOfPoints()
    tubeRadius.SetNumberOfTuples(n)
    tubeRadius.SetName("TubeRadius")
    for i in range(n):
        # We can set the radius based on the given propagated segmentations in that slice?
        # Typically segmentations are elliptical, this could be an issue so for now a constant
        # radius is used
        tubeRadius.SetTuple1(i, radius)

    # Add the scalars to the polydata
    tubePolyData = vtk.vtkPolyData()
    tubePolyData = functionSource.GetOutput()
    tubePolyData.GetPointData().AddArray(tubeRadius)
    tubePolyData.GetPointData().SetActiveScalars("TubeRadius")

    # Create the tubes
    tuber = vtk.vtkTubeFilter()
    tuber.SetInputData(tubePolyData)
    tuber.SetNumberOfSides(50)
    tuber.SetVaryRadiusToVaryRadiusByAbsoluteScalar()
    tuber.Update()

    return tuber
Esempio n. 39
0
    def add_bonds(self,
                  neighbors,
                  center,
                  color=None,
                  opacity=None,
                  radius=0.1):
        """
        Adds bonds for a site.

        Args:
            neighbors: Neighbors of the site.
            center: The site in the center for all bonds.
            color: Color of the tubes representing the bonds
            opacity: Opacity of the tubes representing the bonds
            radius: Radius of tube s representing the bonds
        """
        points = vtk.vtkPoints()
        points.InsertPoint(0, center.x, center.y, center.z)
        n = len(neighbors)
        lines = vtk.vtkCellArray()
        for i in range(n):
            points.InsertPoint(i + 1, neighbors[i].coords)
            lines.InsertNextCell(2)
            lines.InsertCellPoint(0)
            lines.InsertCellPoint(i + 1)
        pd = vtk.vtkPolyData()
        pd.SetPoints(points)
        pd.SetLines(lines)

        tube = vtk.vtkTubeFilter()
        if vtk.VTK_MAJOR_VERSION <= 5:
            tube.SetInputConnection(pd.GetProducerPort())
        else:
            tube.SetInputData(pd)
        tube.SetRadius(radius)

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

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        if opacity is not None:
            actor.GetProperty().SetOpacity(opacity)
        if color is not None:
            actor.GetProperty().SetColor(color)
        self.ren.AddActor(actor)
Esempio n. 40
0
    def __init__(self, data_directory):
        self.color_range = [0, 1]
        bike_filename = os.path.join(data_directory, "bike.vtp")
        tunnel_filename = os.path.join(data_directory, "tunnel.vtu")

        # Seeds settings
        self.resolution = 10
        self.point1 = [-0.4, 0, 0.05]
        self.point2 = [-0.4, 0, 1.5]

        # VTK Pipeline setup
        bikeReader = vtk.vtkXMLPolyDataReader()
        bikeReader.SetFileName(bike_filename)
        bikeReader.Update()
        self.bike_mesh = to_mesh_state(bikeReader.GetOutput())

        tunnelReader = vtk.vtkXMLUnstructuredGridReader()
        tunnelReader.SetFileName(tunnel_filename)
        tunnelReader.Update()

        self.lineSeed = vtk.vtkLineSource()
        self.lineSeed.SetPoint1(*self.point1)
        self.lineSeed.SetPoint2(*self.point2)
        self.lineSeed.SetResolution(self.resolution)

        streamTracer = vtk.vtkStreamTracer()
        streamTracer.SetInputConnection(tunnelReader.GetOutputPort())
        streamTracer.SetSourceConnection(self.lineSeed.GetOutputPort())
        streamTracer.SetIntegrationDirectionToForward()
        streamTracer.SetIntegratorTypeToRungeKutta45()
        streamTracer.SetMaximumPropagation(3)
        streamTracer.SetIntegrationStepUnit(2)
        streamTracer.SetInitialIntegrationStep(0.2)
        streamTracer.SetMinimumIntegrationStep(0.01)
        streamTracer.SetMaximumIntegrationStep(0.5)
        streamTracer.SetMaximumError(0.000001)
        streamTracer.SetMaximumNumberOfSteps(2000)
        streamTracer.SetTerminalSpeed(0.00000000001)

        self.tubeFilter = vtk.vtkTubeFilter()
        self.tubeFilter.SetInputConnection(streamTracer.GetOutputPort())
        self.tubeFilter.SetRadius(0.01)
        self.tubeFilter.SetNumberOfSides(6)
        self.tubeFilter.CappingOn()
        self.tubeFilter.Update()
Esempio n. 41
0
def CreateArrow(point1, point2, tipRatio=0.3):
    """
	Creates an arrow from point1 to point2. Use tipRatio for
	setting the ratio for tip of the arrow.
	"""
    direction = map(lambda x, y: x - y, point2, point1)
    length = math.sqrt(sum(map(lambda x: x**2, direction)))

    unitDir = map(lambda x: x / length, direction)
    shaftDir = map(lambda x: x * (1.0 - tipRatio), unitDir)
    tipPos = map(lambda x: x * (1.0 - (tipRatio * 0.5)), unitDir)

    lineSource = vtkLineSource()
    lineSource.SetPoint1(0, 0, 0)
    lineSource.SetPoint2(shaftDir)

    tubeFilter = vtkTubeFilter()
    tubeFilter.SetInputConnection(lineSource.GetOutputPort())
    tubeFilter.SetRadius(0.02)
    tubeFilter.SetNumberOfSides(8)
    tubeFilter.CappingOn()

    coneSource = vtkConeSource()
    coneSource.CappingOn()
    coneSource.SetHeight(tipRatio)
    coneSource.SetRadius(.2)
    coneSource.SetResolution(16)
    coneSource.SetCenter(tipPos)
    coneSource.SetDirection(tipPos)

    polyCombine = vtkAppendPolyData()
    polyCombine.AddInputConnection(tubeFilter.GetOutputPort())
    polyCombine.AddInputConnection(coneSource.GetOutputPort())
    polyCombine.Update()

    polyMapper = vtkDataSetMapper()
    polyMapper.SetInputConnection(polyCombine.GetOutputPort())

    arrow = vtkActor()
    arrow.SetMapper(polyMapper)
    arrow.SetScale(length)
    arrow.SetPosition(point1)
    arrow.GetProperty().SetColor(1.0, 0.0, 1.0)

    return arrow, polyCombine.GetOutput()
Esempio n. 42
0
def createPipeline(cube,
                   color=(1., 1., 1.),
                   radius=1.0,
                   show_mesh_as_surface=False):
    n0, n1 = cube.data.shape
    numPoints = n0 * n1
    sg = vtk.vtkStructuredGrid()
    pt = vtk.vtkPoints()
    pt.SetNumberOfPoints(numPoints)
    coords = cube.coords()
    lats = coords[0].points
    lons = coords[1].points
    k = 0
    for i1 in range(n1):
        for i0 in range(n0):
            x = radius * math.cos(lats[i0, i1] * math.pi / 180.) * math.cos(
                lons[i0, i1] * math.pi / 180.)
            y = radius * math.cos(lats[i0, i1] * math.pi / 180.) * math.sin(
                lons[i0, i1] * math.pi / 180.)
            z = radius * math.sin(lats[i0, i1] * math.pi / 180.)
            pt.SetPoint(k, x, y, z)
            k += 1

    sg = vtk.vtkStructuredGrid()
    sg.SetDimensions(1, n0, n1)
    sg.SetPoints(pt)
    mp, ac = None, None
    # show mesh as a surface
    if show_mesh_as_surface:
        mp = vtk.vtkDataSetMapper()
        mp.SetInputData(sg)
        ac = vtk.vtkActor()
        ac.SetMapper(mp)
    # show the grid as tubes
    ed = vtk.vtkExtractEdges()
    et = vtk.vtkTubeFilter()
    em = vtk.vtkPolyDataMapper()
    ea = vtk.vtkActor()
    et.SetRadius(0.01)
    ed.SetInputData(sg)
    et.SetInputConnection(ed.GetOutputPort())
    em.SetInputConnection(et.GetOutputPort())
    ea.SetMapper(em)
    ea.GetProperty().SetColor(color)
    return [ea, ac], et, ed, em, sg, pt, mp
Esempio n. 43
0
def main():
    colors = vtk.vtkNamedColors()
    # Create the RenderWindow, Renderer and both Actors
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)
    
    # Create a line
    lineSource = vtk.vtkLineSource()
    lineSource.SetPoint1(0.0, 0.0, 0.0)
    lineSource.SetPoint2(0.0, 1.0, 0.0)
    lineSource.SetResolution(20)
    lineSource.Update()
    
    # Create a tube (cylinder) around the line
    tubeFilter = vtk.vtkTubeFilter()
    tubeFilter.SetInputConnection(lineSource.GetOutputPort())
    tubeFilter.SetRadius(.01) #default is .5
    tubeFilter.SetNumberOfSides(50)
    tubeFilter.Update()
    
    warpTo = vtk.vtkWarpTo()
    warpTo.SetInputConnection(tubeFilter.GetOutputPort())
    warpTo.SetPosition(10, 1, 0)
    warpTo.SetScaleFactor(5)
    warpTo.AbsoluteOn()
    
    mapper = vtk.vtkDataSetMapper()
    mapper.SetInputConnection(warpTo.GetOutputPort())
    mapper.ScalarVisibilityOff()
    
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(colors.GetColor3d('Gold'))

    renderer.SetBackground(colors.GetColor3d('Green'))
    renderer.AddActor(actor)

    renderWindow.SetWindowName('WarpTo')
    renderWindow.Render()

    renderWindowInteractor.Initialize()
    renderWindowInteractor.Start()
Esempio n. 44
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.2, 0.3, 0.4)
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()

        # Create a line
        lineSource = vtk.vtkLineSource()
        lineSource.SetPoint1(1, 0, 0)
        lineSource.SetPoint2(0, 1, 0)

        # Create a mapper and actor
        lineMapper = vtk.vtkPolyDataMapper()
        lineMapper.SetInputConnection(lineSource.GetOutputPort())
        lineActor = vtk.vtkActor()
        lineActor.GetProperty().SetColor(0, 0, 0.1)
        lineActor.SetMapper(lineMapper)

        #Create a tube around the line
        tubeFilter = vtk.vtkTubeFilter()
        tubeFilter.SetInputConnection(lineSource.GetOutputPort())
        tubeFilter.SetRadius(0.025)  #Default is 0.5
        tubeFilter.SetNumberOfSides(50)
        tubeFilter.Update()

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

        # Create an actor
        tubeActor = vtk.vtkActor()
        tubeActor.SetMapper(tubeMapper)

        self.ren.AddActor(tubeActor)
        self.ren.AddActor(lineActor)
        self.ren.ResetCamera()

        self._initialized = False
def helix(startPoint=[0, 0, 0],
          endPoint=[1, 1, 1],
          coils=20,
          r=None,
          thickness=None,
          c='grey',
          alpha=1,
          legend=None,
          texture=None):
    '''
    Build a spring actor of specified nr of coils between startPoint and endPoint
    '''
    diff = endPoint - np.array(startPoint)
    length = np.linalg.norm(diff)
    if not length: return None
    if not r: r = length / 20
    trange = np.linspace(0, length, num=50 * coils)
    om = 6.283 * (coils - .5) / length
    pts = [[r * np.cos(om * t), r * np.sin(om * t), t] for t in trange]
    pts = [[0, 0, 0]] + pts + [[0, 0, length]]
    diff = diff / length
    theta = np.arccos(diff[2])
    phi = np.arctan2(diff[1], diff[0])
    sp = vu.polydata(line(pts), False)
    t = vtk.vtkTransform()
    t.RotateZ(phi * 57.3)
    t.RotateY(theta * 57.3)
    tf = vtk.vtkTransformPolyDataFilter()
    vu.setInput(tf, sp)
    tf.SetTransform(t)
    tf.Update()
    tuf = vtk.vtkTubeFilter()
    tuf.SetNumberOfSides(12)
    tuf.CappingOn()
    vu.setInput(tuf, tf.GetOutput())
    if not thickness: thickness = r / 10
    tuf.SetRadius(thickness)
    tuf.Update()
    poly = tuf.GetOutput()
    actor = vu.makeActor(poly, c, alpha, legend=legend, texture=texture)
    actor.GetProperty().SetInterpolationToPhong()
    actor.SetPosition(startPoint)
    setattr(actor, 'base', np.array(startPoint))
    setattr(actor, 'top', np.array(endPoint))
    return actor
Esempio n. 46
0
def generate_plane_path():
    """
    Generate the plane path
    :return: the actor of the plane path
    """
    size, coordinates = read_txt(VTK_PLANE_GPS)

    plane_points = vtk.vtkPoints()
    plane_lines = vtk.vtkPolyLine()
    plane_lines.GetPointIds().SetNumberOfIds(int(size))
    scalar = vtk.vtkFloatArray()

    previous_alt = coordinates[0][2]

    for i, (x, y, alt) in enumerate(coordinates):
        lat, long = convert_rt90_to_gps_coordinate(x, y)
        plane_points.InsertNextPoint(coordinate_earth(lat, long, alt))
        plane_lines.GetPointIds().SetId(i, i)

        delta_alt = previous_alt - alt
        scalar.InsertNextValue(delta_alt)
        previous_alt = alt

    min_scalar, max_scalar = scalar.GetValueRange()

    plane_cells = vtk.vtkCellArray()
    plane_cells.InsertNextCell(plane_lines)

    plane_data = vtk.vtkPolyData()
    plane_data.SetPoints(plane_points)
    plane_data.SetLines(plane_cells)
    plane_data.GetPointData().SetScalars(scalar)

    plane_tube = vtk.vtkTubeFilter()
    plane_tube.SetRadius(35)
    plane_tube.SetInputData(plane_data)

    plane_mapper = vtk.vtkPolyDataMapper()
    plane_mapper.SetInputConnection(plane_tube.GetOutputPort())
    plane_mapper.SetScalarRange(min_scalar, max_scalar)

    plane_actor = vtk.vtkActor()
    plane_actor.SetMapper(plane_mapper)

    return plane_actor
def createSourceFromPoint(node):
    if node.parent is None:
        px = node.x
        py = node.y
        pz = node.z - node.length
    else:
        px = node.parent.x
        py = node.parent.y
        pz = node.parent.z
    source = vtk.vtkLineSource()
    source.SetPoint1(px, py, pz)
    source.SetPoint2(node.x, node.y, node.z)
    tube = vtk.vtkTubeFilter()
    tube.SetRadius(2 * node.model.length_ratio**node.level)
    tube.SetNumberOfSides(100)
    tube.CappingOn()
    tube.SetInputConnection(source.GetOutputPort())
    return tube
Esempio n. 48
0
    def CreateCylinder(self, p1, p2, r=30, color=(1.0, 1.0, 1.0)):
        x, y, h = p1[0], p1[1], p2[2]
        line = vtk.vtkLineSource()
        line.SetPoint1(x, y, 0)
        line.SetPoint2(x, y, h)

        tubefilter = vtk.vtkTubeFilter()
        tubefilter.SetInputConnection(line.GetOutputPort())
        tubefilter.SetRadius(r)
        tubefilter.SetNumberOfSides(30)
        tubefilter.CappingOn()

        cylinderMapper = vtk.vtkPolyDataMapper()
        cylinderMapper.SetInputConnection(tubefilter.GetOutputPort())
        cylinderActor = vtk.vtkActor()
        cylinderActor.GetProperty().SetColor(color)
        cylinderActor.SetMapper(cylinderMapper)
        return cylinderActor
Esempio n. 49
0
def plot_roots(pd, p_name, win_title="", render=True):
    """ plots the root system 
    @param pd         the polydata representing the root system (lines, or polylines)
    @param p_name     parameter name of the data to be visualized
    @param win_title  the windows titles (optionally, defaults to p_name)
    @param render     render in a new interactive window (default = True)
    @return a tuple of a vtkActor and the corresponding color bar vtkScalarBarActor
    """
    if isinstance(pd, pb.RootSystem):
        pd = segs_to_polydata(pd, 1., [p_name, "radius"])

    if isinstance(pd, pb.SegmentAnalyser):
        pd = segs_to_polydata(pd, 1., [p_name, "radius"])

    if win_title == "":
        win_title = p_name

    pd.GetPointData().SetActiveScalars("radius")  # for the the filter
    tubeFilter = vtk.vtkTubeFilter()
    tubeFilter.SetInputData(pd)
    tubeFilter.SetNumberOfSides(9)  #
    tubeFilter.SetVaryRadiusToVaryRadiusByAbsoluteScalar()
    tubeFilter.Update()

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(tubeFilter.GetOutputPort())
    mapper.Update()
    mapper.ScalarVisibilityOn()
    mapper.SetScalarModeToUseCellFieldData(
    )  # maybe because radius is active scalar in point data?
    mapper.SetArrayName(p_name)
    mapper.SelectColorArray(p_name)
    mapper.UseLookupTableScalarRangeOn()
    plantActor = vtk.vtkActor()
    plantActor.SetMapper(mapper)

    lut = create_lookup_table()  # 24
    scalar_bar = create_scalar_bar(lut, pd, p_name)  # vtkScalarBarActor
    mapper.SetLookupTable(lut)

    if render:
        render_window(plantActor, win_title, scalar_bar,
                      pd.GetBounds()).Start()
    return plantActor, scalar_bar
Esempio n. 50
0
    def updateRegistration(self, rmse, mat, newContours):
        print('RMSE: %f' % (rmse))
        # We cannot call Inverse on transform, since it is an ICP and will
        # issue a registration where source and target are interchanged
        #mat = vtk.vtkMatrix4x4()
        #mat.DeepCopy(transform.GetMatrix())

        self.regAlignment.SetMatrix(mat)
        self.regAlignment.Inverse()

        for i in range(len(self.viewUS)):
            self.viewUS[i].UpdateContours()
            self.viewUS[i].viewer.GetResliceCursorWidget().Render()

        if self.usCorrectedActor is not None:
            self.viewer3D.interactor.Disable()
            self.viewer3D.planeWidgets[0].GetDefaultRenderer().RemoveActor(
                self.usCorrectedActor)
            self.viewer3D.interactor.Enable()
            self.usCorrectedActor = None

        # Tube filter and color them green
        tubes = vtk.vtkTubeFilter()
        tubes.SetInputData(newContours)
        tubes.CappingOn()
        tubes.SidesShareVerticesOff()
        tubes.SetNumberOfSides(12)
        tubes.SetRadius(1.0)

        edgeMapper = vtk.vtkPolyDataMapper()
        edgeMapper.SetInputConnection(tubes.GetOutputPort())
        edgeMapper.ScalarVisibilityOff()

        self.usCorrectedActor = vtk.vtkActor()
        self.usCorrectedActor.SetMapper(edgeMapper)
        prop = self.usCorrectedActor.GetProperty()
        prop.SetColor(yellow)

        self.viewer3D.planeWidgets[0].GetDefaultRenderer().AddActor(
            self.usCorrectedActor)

        self.btnReg.setEnabled(True)
        self.Render()
Esempio n. 51
0
 def drawEdge(self, actor, source, target, color):
     e = vtk.vtkPolyData()
     p = vtk.vtkPoints()
     p.InsertPoint(0, source[0], source[1], source[2])
     p.InsertPoint(1, target[0], target[1], target[2])
     e.SetPoints(p)
     c = vtk.vtkCellArray()
     c.InsertNextCell(2)
     c.InsertCellPoint(0)
     c.InsertCellPoint(1)
     e.SetLines(c)
     edge = vtk.vtkTubeFilter()
     edge.SetRadius(0.01)
     edge.SetNumberOfSides(10)
     edge.SetInput(e)
     actor.GetProperty().SetColor(color)
     mapper = vtk.vtkPolyDataMapper()
     mapper.SetInputConnection(edge.GetOutputPort())
     actor.SetMapper(mapper)
Esempio n. 52
0
    def ReturnTubeGlyphActorFromPoints(self, MyPoints, MyLines, TubeRadius,
                                       color):
        inputDataGlyph = vtk.vtkPolyData()
        glyphMapper = vtk.vtkPolyDataMapper()
        #        glyphPoints = vtk.vtkGlyph3D()
        tubes = vtk.vtkTubeFilter()
        inputDataGlyph.SetPoints(MyPoints)
        inputDataGlyph.SetLines(MyLines)
        tubes.SetInputData(inputDataGlyph)
        tubes.SetRadius(TubeRadius)

        #        glyphPoints.SetSourceConnection(tubes.GetOutputPort())
        glyphMapper.SetInputConnection(tubes.GetOutputPort())
        glyphActor = vtk.vtkActor()
        glyphActor.SetMapper(glyphMapper)
        glyphActor.GetProperty().SetDiffuseColor(color)
        glyphActor.GetProperty().SetSpecular(.3)
        glyphActor.GetProperty().SetSpecularPower(30)
        return glyphActor
Esempio n. 53
0
    def __init__(self,
                 p1=(0, 0, 0),
                 p2=(1, 1, 1),
                 radius=0.1,
                 color=(0, 1, 1)):
        self.src = vtk.vtkLineSource()
        self.src.SetPoint1(p1)
        self.src.SetPoint2(p2)

        self.tubefilter = vtk.vtkTubeFilter()
        self.tubefilter.SetInputConnection(self.src.GetOutputPort())
        self.tubefilter.SetRadius(radius)
        self.tubefilter.SetNumberOfSides(30)
        self.tubefilter.Update()

        self.mapper = vtk.vtkPolyDataMapper()
        self.mapper.SetInputConnection(self.tubefilter.GetOutputPort())
        self.SetMapper(self.mapper)
        self.SetColor(color)
Esempio n. 54
0
def plot_roots(pd, p_name, render=True):
    """ renders the root system in an interactive window 
    @param pd         the polydata representing the root system
    @param p_name      parameter name of the data to be visualized
    @param render     render in a new interactive window (default = True)
    @return The vtkActor object
    """
    pd.GetPointData().SetActiveScalars("radius")  # for the the filter
    tubeFilter = vtk.vtkTubeFilter()
    tubeFilter.SetInputData(pd)
    tubeFilter.SetNumberOfSides(9)
    tubeFilter.SetVaryRadiusToVaryRadiusByAbsoluteScalar()
    tubeFilter.Update()

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(tubeFilter.GetOutputPort())
    mapper.Update()
    mapper.ScalarVisibilityOn()
    mapper.SetScalarModeToUseCellFieldData()  # Cell is not working
    mapper.SetArrayName(p_name)
    mapper.SelectColorArray(p_name)
    mapper.UseLookupTableScalarRangeOn()

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

    lut = get_lookup_table(24)  # 24= Brewer Diverging Brown-Blue-Green (11)
    lut.SetTableRange(pd.GetPointData().GetScalars(p_name).GetRange())
    mapper.SetLookupTable(lut)

    scalarBar = vtk.vtkScalarBarActor()
    scalarBar.SetLookupTable(lut)
    scalarBar.SetTitle(p_name)
    textProperty = vtk.vtkTextProperty()
    textProperty.SetFontSize(1)
    scalarBar.SetTitleTextProperty(textProperty)
    scalarBar.SetLabelTextProperty(textProperty)
    #    scalarBar.SetAnnotationTextProperty(textProperty)

    if render:
        render_window(plantActor, pname, scalarBar)
    return plantActor, scalarBar
Esempio n. 55
0
    def addPolyLine(self,
                    points,
                    color,
                    thick=False,
                    thickness=_DEFAULT_LINE_THICKNESS):
        vtkPoints = vtk.vtkPoints()
        for point in points:
            vtkPoints.InsertNextPoint(point[0], point[1], point[2])

        if thick:
            cellArray = vtk.vtkCellArray()
            cellArray.InsertNextCell(len(points))
            for i in range(len(points)):
                cellArray.InsertCellPoint(i)

            polyData = vtk.vtkPolyData()
            polyData.SetPoints(vtkPoints)
            polyData.SetLines(cellArray)

            tubeFilter = vtk.vtkTubeFilter()
            tubeFilter.SetNumberOfSides(8)
            tubeFilter.SetInputData(polyData)
            tubeFilter.SetRadius(thickness)
            tubeFilter.Update()

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

        else:
            unstructuredGrid = vtk.vtkUnstructuredGrid()
            unstructuredGrid.SetPoints(vtkPoints)
            for i in range(1, len(points)):
                unstructuredGrid.InsertNextCell(vtk.VTK_LINE, 2, [i - 1, i])

            mapper = vtk.vtkDataSetMapper()
            mapper.SetInputData(unstructuredGrid)

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetColor(color)

        self._rendererScene.AddActor(actor)
Esempio n. 56
0
def createActors(vtkPoints, colors):
    """ Create the actors to display the trajectory. It uses a PolyLine and
    a TubeFilter.
    Args:
        vtkPoints - VtkPoints
        colors - Array of colors
    Returns:
        tuple of actors, one for the PolyLine and one for the TubeFilter.
    """
    polyLine = vtk.vtkPolyLine()
    polyLine.GetPointIds().SetNumberOfIds(vtkPoints.GetNumberOfPoints())
    for i in range(0, vtkPoints.GetNumberOfPoints()):
        polyLine.GetPointIds().SetId(i, i)

    cells = vtk.vtkCellArray()
    cells.InsertNextCell(polyLine)

    polyData = vtk.vtkPolyData()
    polyData.SetPoints(vtkPoints)
    polyData.SetLines(cells)
    polyData.GetPointData().SetScalars(colors)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(polyData)

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

    # Create a tube (cylinder) around the line
    tubeFilter = vtk.vtkTubeFilter()
    tubeFilter.SetInputData(polyData)
    tubeFilter.SetRadius(20)
    tubeFilter.SetNumberOfSides(50)
    tubeFilter.Update()

    # Create a mapper and actor
    tubeMapper = vtk.vtkPolyDataMapper()
    tubeMapper.SetInputConnection(tubeFilter.GetOutputPort())
    tubeActor = vtk.vtkActor()
    tubeActor.SetMapper(tubeMapper)

    return (actor, tubeActor)
Esempio n. 57
0
def create_renderer_1(bone, skin, spacing):
    '''
    Return the first renderer
    bone: the bone dataset
    skin: the skin dataset
    spacing: distances between points of the original data
    '''
    # creating actors
    bone_actor = create_actor(bone)
    bone_actor.GetProperty().SetColor(0.94, 0.94, 0.94)

    # creating the plane to cut the skin
    plane = vtk.vtkPlane()
    center = skin.GetOutput().GetCenter()
    # origin is set to the center
    plane.SetOrigin(center[0], center[1], center[2])
    plane.SetNormal(0, 0, 1)

    # creating the cutter
    cutter = vtk.vtkCutter()
    cutter.SetCutFunction(plane)
    size = skin.GetOutput().GetBounds()[5]
    # 19 tube, 1 centered, 9 for each side. 1 centimeter is 10 voxel height
    cutter.GenerateValues(19, -spacing[2] * 10 * 9, spacing[2] * 10 * 9)
    cutter.SetInputConnection(skin.GetOutputPort())

    # making it as a tube
    # using a stripper makes the tube smoother
    stripper = vtk.vtkStripper()
    stripper.SetInputConnection(cutter.GetOutputPort())
    tubeFilter = vtk.vtkTubeFilter()
    tubeFilter.SetRadius(1)
    tubeFilter.SetInputConnection(stripper.GetOutputPort())

    cutter_actor = create_actor(tubeFilter)
    cutter_actor.GetProperty().SetColor(0.8, 0.62, 0.62)

    # creating renderer
    ren = create_renderer([bone_actor, cutter_actor])
    ren.SetBackground(1, 0.827, 0.824)

    return ren
Esempio n. 58
0
    def BuildTube(self):
        self.tubeFilter = vtk.vtkTubeFilter()
        self.tubeFilter.SetInput(self.polyData)
        self.tubeFilter.SetRadius(0.1)
        self.Properties.append(
            Properties.FloatProperty("tube radius", self.tubeFilter.SetRadius,
                                     self.tubeFilter.GetRadius))
        self.tubeFilter.SetNumberOfSides(12)
        self.tubeFilter.CappingOn()

        map = vtk.vtkPolyDataMapper()
        map.SetInput(self.tubeFilter.GetOutput())

        self.lineActor = vtk.vtkActor()
        self.lineActor.SetMapper(map)
        self.lineActor.GetProperty().SetColor(1, .2, .2)
        self.Properties.append(
            Properties.ColorProperty("tube color",
                                     self.lineActor.GetProperty().SetColor,
                                     self.lineActor.GetProperty().GetColor))
Esempio n. 59
0
    def SetupProfile(self):
        self.profileData = vtk.vtkPolyData()

        self.tubes = vtk.vtkTubeFilter()
        self.tubes.SetNumberOfSides(
            Globals.renderProps["profileNumberOfSides"])
        self.tubes.SetInput(self.profileData)
        self.tubes.SetRadius( \
            Globals.renderProps["tubeSize"]
            * Globals.referenceSize )

        self.profileMapper = vtk.vtkPolyDataMapper()
        self.profileMapper.SetInputConnection(self.tubes.GetOutputPort())

        self.profile = vtk.vtkActor()
        self.profile.SetMapper(self.profileMapper)

        Globals.ren.AddActor(self.profile)
        self.profile.GetProperty().SetOpacity( \
            Globals.renderProps["opacity"] )
Esempio n. 60
0
def getAxes(Origin, scale=1):
    axes = vtk.vtkAxes()
    axes.SetOrigin(*Origin)
    axes.SetScaleFactor(scale)

    axesTubes = vtk.vtkTubeFilter()

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

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

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

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

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

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

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

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

    YActor = vtk.vtkFollower()
    YActor.SetMapper(YTextMapper)
    YActor.SetScale(.1, .1, .1)
    YActor.SetPosition(Origin[0], 1, Origin[2])
    YActor.GetProperty().SetColor(0, 0, 0)
    return axesActor, XActor, YActor