Exemplo n.º 1
0
 def add_outline(self):
     outline = vtk.vtkOutlineFilter()
     outline.SetInputData(self.data.grid[self.current_timestep])
     outline_mapper = vtk.vtkDataSetMapper()
     outline_mapper.SetInputConnection(outline.GetOutputPort())
     self.outline_actor.SetMapper(outline_mapper)
     self.ren.AddActor(self.outline_actor)
Exemplo n.º 2
0
    def __init__(self, parent, visualizer, **kws):
        """
		Method: __init__(parent)
		Initialization
		"""
        self.x, self.y, self.z = -1, -1, -1
        VisualizationModule.__init__(self, parent, visualizer, **kws)
        #self.name = "Arbitrary Slices"
        self.on = 0
        self.renew = 1
        self.mapper = vtk.vtkPolyDataMapper()

        self.outline = vtk.vtkOutlineFilter()
        self.outlineMapper = vtk.vtkPolyDataMapper()
        self.outlineActor = vtk.vtkActor()
        self.outlineActor.SetMapper(self.outlineMapper)

        self.picker = vtk.vtkCellPicker()
        self.picker.SetTolerance(0.5)

        self.planes = []
        self.renderer = self.parent.getRenderer()
        self.renderer.AddActor(self.outlineActor)

        self.ctf = None
        self.origin = None
        self.spacing = None
        self.extent = None
Exemplo n.º 3
0
  def SetInput(self, input) :
    img = image(input)
    self.__input__ = img
    if img :
      # Update to try to avoid to exit if a c++ exception is throwed
      # sadely, it will not prevent the program to exit later...
      # a real fix would be to wrap c++ exception in vtk
      img.UpdateOutputInformation()
      img.Update()
      import itk
      self.__flipper__ = itk.FlipImageFilter[img].New(Input=img)
      axes = self.__flipper__.GetFlipAxes()
      axes.SetElement(1, True)
      self.__flipper__.SetFlipAxes(axes)
      self.__itkvtkConverter__ = itk.ImageToVTKImageFilter[img].New(self.__flipper__)
      self.__volumeMapper__.SetInput(self.__itkvtkConverter__.GetOutput())
      # needed to avoid warnings
      # self.__itkvtkConverter__.GetOutput() must be callable
      import vtk
      if not self.__outline__ :
	  self.__outline__ = vtk.vtkOutlineFilter()
	  self.__outline__.SetInput(self.__itkvtkConverter__.GetOutput())
	  self.__outlineMapper__ = vtk.vtkPolyDataMapper()
	  self.__outlineMapper__.SetInput(self.__outline__.GetOutput())
	  self.__outlineActor__ = vtk.vtkActor()
	  self.__outlineActor__.SetMapper(self.__outlineMapper__)
	  self.__ren__.AddActor(self.__outlineActor__)
      else :
	  self.__outline__.SetInput(self.__itkvtkConverter__.GetOutput())

    self.Render()
Exemplo n.º 4
0
    def readStl(self, name):
        self.reader = vtk.vtkSTLReader()
        self.reader.SetFileName(str(name))

        logger.log.info('STL file <b><font color=%s>' % (LOGCOLOR) +
                        str(name) + '</b> loaded')

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

        self.actor = vtk.vtkActor()
        self.actor.SetMapper(self.mapper)
        self.actor.GetProperty().SetColor(0, 1, 0.2)  # (R,G,B)
        self.actor.GetProperty().SetLineWidth(2.0)

        # create outline mapper
        self.outl = vtk.vtkOutlineFilter()
        self.outl.SetInputConnection(self.reader.GetOutputPort())
        self.outlineMapper = vtk.vtkPolyDataMapper()
        self.outlineMapper.SetInputConnection(self.outl.GetOutputPort())

        # create outline actor
        self.outlineActor = vtk.vtkActor()
        self.outlineActor.SetMapper(self.outlineMapper)

        self.renderer.AddActor(self.actor)
        self.renderer.ResetCamera()

        self.setDisplay('shaded')
        self.setShading('gouraud')

        # set tab to VTK window after loading an STL file
        ntabs = self.parent.centralwidget.tabs.count()
        self.parent.centralwidget.tabs.setCurrentIndex(ntabs - 1)
Exemplo n.º 5
0
    def __init__(self, reader):
        self.reader = reader

        sg = self.src_glyph = vtk.vtkSphereSource()
        sg.SetRadius(0.5)
        sg.SetCenter(0.5, 0.0, 0.0)

        g = self.glyph = vtk.vtkTensorGlyph()
        g.SetInputConnection(self.reader.GetOutputPort())
        g.SetSourceConnection(self.src_glyph.GetOutputPort())
        g.SetScaleFactor(0.25)

        # The normals are needed to generate the right colors and if
        # not used some of the glyphs are black.
        self.normals = vtk.vtkPolyDataNormals()
        self.normals.SetInputConnection(g.GetOutputPort())

        self.map = vtk.vtkPolyDataMapper()
        self.map.SetInputConnection(self.normals.GetOutputPort())

        self.act = vtk.vtkActor()
        self.act.SetMapper(self.map)

        # An outline.
        self.of = vtk.vtkOutlineFilter()
        self.of.SetInputConnection(self.reader.GetOutputPort())

        self.out_map = vtk.vtkPolyDataMapper()
        self.out_map.SetInputConnection(self.of.GetOutputPort())

        self.out_act = vtk.vtkActor()
        self.out_act.SetMapper(self.out_map)
Exemplo n.º 6
0
 def add_outline(self):
     outline = vtk.vtkOutlineFilter()
     outline.SetInputData(self.data.grid[self.current_timestep])
     outline_mapper = vtk.vtkDataSetMapper()
     outline_mapper.SetInputConnection(outline.GetOutputPort())
     self.outline_actor.SetMapper(outline_mapper)
     self.ren.AddActor(self.outline_actor)
Exemplo n.º 7
0
def CreateOutline(source, actor):
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(source.GetOutputPort())
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(outline.GetOutputPort())
    actor.SetMapper(mapper)
    return
Exemplo n.º 8
0
def task1(InputData):
    #print(InputData.GetOutput())
    # create a BoundingBox using
    # vtkOutlineFilter
    # vtkPolyDataMapper
    # vtkActor

    #BBox_poly = vtk.vtkPolyData()
    #BBox_poly.SetPoints(bbox_points)

    #outlineDimTmp=InputData.GetDimensions()
    # img = vtk.vtkXMLImageDataWriter()
    # img.SetFileName(InputData)

    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(InputData.GetOutputPort())

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

    outActor = vtk.vtkActor()
    outActor.SetMapper(outline_mapper)
    outActor.GetProperty().SetColor(0, 128, 0)
    outActor.GetProperty().SetLineWidth(3)
    #print("task1")
    return outActor
Exemplo n.º 9
0
    def __init__(self, reader):
        self.reader = reader
        sg = self.src_glyph = vtk.vtkSphereSource()
        sg.SetRadius(0.5)
        sg.SetCenter(0.5, 0.0, 0.0)
        g = self.glyph = vtk.vtkTensorGlyph()        
        g.SetInputConnection(self.reader.GetOutputPort())
        g.SetSource(self.src_glyph.GetOutput())
        g.SetScaleFactor(0.25)
        
        # The normals are needed to generate the right colors and if
        # not used some of the glyphs are black.        
        self.normals = vtk.vtkPolyDataNormals()
        self.normals.SetInputConnection(g.GetOutputPort())
        self.map = vtk.vtkPolyDataMapper()
        self.map.SetInputConnection(self.normals.GetOutputPort())        
        self.act = vtk.vtkActor()
        self.act.SetMapper(self.map)

        # An outline.
        self.of = vtk.vtkOutlineFilter()
        self.of.SetInputConnection(self.reader.GetOutputPort())
        self.out_map = vtk.vtkPolyDataMapper()
        self.out_map.SetInputConnection(self.of.GetOutputPort())
        self.out_act = vtk.vtkActor()
        self.out_act.SetMapper(self.out_map)        
Exemplo n.º 10
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkOutlineFilter(), 'Processing.',
         ('vtkDataSet',), ('vtkPolyData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
Exemplo n.º 11
0
def main():
    colors = vtk.vtkNamedColors()

    aren = vtk.vtkRenderer()

    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(aren)

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

    #
    # Create surfaces F(x,y,z) = constant
    #
    # Sample quadric function
    quadric = vtk.vtkQuadric()
    quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0)
    sample = vtk.vtkSampleFunction()
    sample.SetSampleDimensions(50, 50, 50)
    sample.SetImplicitFunction(quadric)

    contour = vtk.vtkContourFilter()
    contour.SetInputConnection(sample.GetOutputPort())
    contour.GenerateValues(5, 0, 1.2)

    contourMapper = vtk.vtkPolyDataMapper()
    contourMapper.SetInputConnection(contour.GetOutputPort())
    contourMapper.SetScalarRange(0, 1.2)

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

    # Create outline
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(sample.GetOutputPort())

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

    outlineActor = vtk.vtkActor()
    outlineActor.SetMapper(outlineMapper)
    outlineActor.GetProperty().SetColor(colors.GetColor3d("Brown"))
    outlineActor.GetProperty().SetLineWidth(3.0)

    #
    # Rendering stuff
    #
    aren.SetBackground(colors.GetColor3d("SlateGray"))
    aren.AddActor(contourActor)
    aren.AddActor(outlineActor)

    aren.ResetCamera()
    aren.GetActiveCamera().Azimuth(30)
    aren.GetActiveCamera().Elevation(30)

    renWin.SetSize(640, 512)
    renWin.Render()

    # interact with data
    iren.Start()
Exemplo n.º 12
0
def setup_renderer(renderer, actors, bboxpolydata=None):
    ren = renderer
    for actor in actors:
        # assign actor to the renderer
        ren.AddActor(actor)
    ############################################
    # Create a vtkOutlineFilter to draw the bounding box of the data set.
    # Also create the associated mapper and actor.
    if bboxpolydata is not None:
        outline = vtk.vtkOutlineFilter()
        outline.SetInput(bboxpolydata.GetOutput())
        mapOutline = vtk.vtkPolyDataMapper()
        mapOutline.SetInputConnection(outline.GetOutputPort())
        outlineActor = vtk.vtkActor()
        outlineActor.SetMapper(mapOutline)
        outlineActor.GetProperty().SetColor(100, 100, 100)
        ren.AddViewProp(outlineActor)
        ren.AddActor(outlineActor)

    # Create a vtkLight, and set the light parameters.
    #light = vtk.vtkLight()
    #light.SetFocalPoint(0.21406, 1.5, 0)
    #light.SetPosition(8.3761, 4.94858, 4.12505)
    #ren.AddLight(light)
    return ren
Exemplo n.º 13
0
    def DrawVoxelArray(self, arrayBuffer):
        #reshape
        resolution = self.VolumeMgr.resolution
        sample = arrayBuffer.reshape(1, 1, resolution, resolution, resolution)
        dataMatrix = self.MakeDataMatrix( np.asarray(sample, dtype=np.uint8), 255)

        data_string = dataMatrix.tostring()
        dataImporter = vtk.vtkImageImport()
        dataImporter.CopyImportVoidPointer(data_string, len(data_string))
        dataImporter.SetDataScalarTypeToUnsignedChar()
        dataImporter.SetNumberOfScalarComponents(1)
        dataImporter.SetDataExtent(0, int(dim * v_res)-1, 0, int(dim * v_res)-1, 0, int(dim * v_res)-1)
        dataImporter.SetWholeExtent(0, int(dim * v_res)-1, 0, int(dim * v_res)-1, 0, int(dim * v_res)-1)

        self.VolumeMgr.AddVolumeData(dataImporter.GetOutputPort())
        #Display BoundignBox
        boundingBox = vtk.vtkOutlineFilter()
        boundingBox.SetInputData(dataImporter.GetOutput())

        bbmapper = vtk.vtkPolyDataMapper()
        bbmapper.SetInputConnection(boundingBox.GetOutputPort())

        bbActor = vtk.vtkActor()
        bbActor.SetMapper(bbmapper)
        bbActor.GetProperty().SetColor(1, 0, 0)

        self.renderer.AddActor(bbActor)

        self.Redraw()
Exemplo n.º 14
0
def PlotFunction(quadric, value):
    colors = vtk.vtkNamedColors()

    # sample the quadric function
    sample = vtk.vtkSampleFunction()
    sample.SetSampleDimensions(50, 50, 50)
    sample.SetImplicitFunction(quadric)
    # double xmin = 0, xmax=1, ymin=0, ymax=1, zmin=0, zmax=1
    xmin = -10
    xmax = 11
    ymin = -10
    ymax = 10
    zmin = -10
    zmax = 10
    sample.SetModelBounds(xmin, xmax, ymin, ymax, zmin, zmax)

    # create the 0 isosurface
    contours = vtk.vtkContourFilter()
    contours.SetInputConnection(sample.GetOutputPort())
    contours.GenerateValues(1, value, value)

    # map the contours to graphical primitives
    contourMapper = vtk.vtkPolyDataMapper()
    contourMapper.SetInputConnection(contours.GetOutputPort())
    contourMapper.SetScalarRange(0.0, 1.2)

    # create an actor for the contours
    contourActor = vtk.vtkActor()
    contourActor.SetMapper(contourMapper)

    # -- create a box around the function to indicate the sampling volume --

    # create outline
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(sample.GetOutputPort())

    # map it to graphics primitives
    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInputConnection(outline.GetOutputPort())

    # create an actor for it
    outlineActor = vtk.vtkActor()
    outlineActor.SetMapper(outlineMapper)
    outlineActor.GetProperty().SetColor(colors.GetColor3d('Black'))

    # setup the window
    ren1 = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren1)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # add the actors to the scene
    ren1.AddActor(contourActor)
    ren1.AddActor(outlineActor)
    ren1.SetBackground(colors.GetColor3d('AliceBlue'))

    # render and interact
    renWin.Render()
    iren.Start()
    def build_real_bbox(self, molecule):
        
        Xmin,Xmax,Ymin, Ymax, Zmin, Zmax = molecule.GetBounds()
        bbox_points = vtk.vtkPoints()
         
        bbox_points.InsertNextPoint(Xmin, Ymin, Zmin)
        bbox_points.InsertNextPoint(Xmax , Ymax, Zmax)
         
        BBox_poly = vtk.vtkPolyData()
        BBox_poly.SetPoints(bbox_points)
         
        outline = vtk.vtkOutlineFilter()
        if vtk.vtkVersion.GetVTKMajorVersion()<6:
            outline.SetInput(BBox_poly)
        else:
            outline.SetInputData(BBox_poly)

        outline_mapper = vtk.vtkPolyDataMapper()
        outline_mapper.SetInputConnection(outline.GetOutputPort())
        
        outline_actor = vtk.vtkActor()
        outline_actor.SetMapper(outline_mapper)
        outline_actor.GetProperty().SetColor(1,0,0)
        outline_actor.GetProperty().SetLineWidth(3)
        
        self._renderer.AddActor(outline_actor)
        self._iren.Render()
Exemplo n.º 16
0
def vtk_render_window(ren, iso, img=None, color=[0.5, 0.5, 0.5]):
    normals = vtk.vtkPolyDataNormals()
    normals.SetInputConnection(iso.GetOutputPort())
    normals.FlipNormalsOn()
    isoMapper = vtk.vtkPolyDataMapper()
    isoMapper.SetInputConnection(normals.GetOutputPort())
    isoMapper.ScalarVisibilityOff()

    isoActor = vtk.vtkActor()
    isoActor.SetMapper(isoMapper)
    isoActor.GetProperty().SetColor(color)

    # Add the actors to the renderer, set the background and size
    if img != None:
        outline = vtk.vtkOutlineFilter()
        outline.SetInputConnection(img.GetOutputPort())
        outlineMapper = vtk.vtkPolyDataMapper()
        outlineMapper.SetInputConnection(outline.GetOutputPort())
        outlineActor = vtk.vtkActor()
        outlineActor.SetMapper(outlineMapper)
        outlineActor.VisibilityOff()
        ren.AddActor(outlineActor)

    ren.AddActor(isoActor)
    return ren
    def build_bbox(self, basis_vector):
        
        cell = numpy.array(basis_vector).astype(numpy.float32)
        Xmax,Ymax,Zmax =  numpy.array([cell[0,0], cell[1,1], cell[2,2]], dtype = numpy.float32)
        bbox_points = vtk.vtkPoints()
        
        self.cell_bounds_coords = numpy.array([-Xmax/2. , Xmax/2.,  -Ymax/2., Ymax/2.,  -Zmax/2., Zmax/2.])
        
        bbox_points.InsertNextPoint(-Xmax/2. , -Ymax/2., -Zmax/2.)
        bbox_points.InsertNextPoint(Xmax/2. , Ymax/2., Zmax/2.)
         
        BBox_poly = vtk.vtkPolyData()
        BBox_poly.SetPoints(bbox_points)
         
        outline = vtk.vtkOutlineFilter()
        if vtk.vtkVersion.GetVTKMajorVersion()<6:
            outline.SetInput(BBox_poly)
        else:
            outline.SetInputData(BBox_poly)

        outline_mapper = vtk.vtkPolyDataMapper()
        outline_mapper.SetInputConnection(outline.GetOutputPort())
        
        outline_actor = vtk.vtkActor()
        outline_actor.SetMapper(outline_mapper)
        outline_actor.GetProperty().SetColor(1,1,1)
        outline_actor.GetProperty().SetLineWidth(3)
        
        return outline_actor
 def __init__(self,viewer, selection_color):
     self.viewer = viewer
     self.selection_color = selection_color
     outline = vtk.vtkOutlineFilter()
     if vtk.vtkVersion.GetVTKMajorVersion()<6:
         outline.SetInput(self.viewer._polydata)
     else:
         outline.SetInputData(self.viewer._polydata)
                 
     outlineMapper = vtk.vtkPolyDataMapper()
     outlineMapper.SetInputConnection(outline.GetOutputPort())
     self.box=vtk.vtkActor()
     self.box.SetMapper( outlineMapper )
     self.box.GetProperty().SetColor(1,1,1)
     self.box.PickableOff()
     
     self.SetProp3D(self.box)
     self.planes=vtk.vtkPlanes()
     self.SetInteractor(viewer.iren)
     if vtk.vtkVersion.GetVTKMajorVersion()<6:
         self.SetInput(self.viewer._polydata)
     else:
         self.SetInputData(self.viewer._polydata)
         
     self.SetPlaceFactor(1)
     self.PlaceWidget()
     self.InsideOutOn()
     self.SetRotationEnabled(0)
     self.GetPlanes(self.planes)
     self.AddObserver("EndInteractionEvent",self.on_select_atoms)
Exemplo n.º 19
0
    def load(self):
        self.reader = vtk.vtkSTLReader()
        self.reader.SetFileName(str(self.filename))

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

        #create model actor
        self.actor = vtk.vtkActor()
        self.actor.GetProperty().SetColor(1, 1, 1)
        self.actor.GetProperty().SetOpacity(1)
        self.actor.SetMapper(self.mapper)

        #create outline mapper
        self.outline = vtk.vtkOutlineFilter()
        self.outline.SetInputConnection(self.reader.GetOutputPort())
        self.outlineMapper = vtk.vtkPolyDataMapper()
        self.outlineMapper.SetInputConnection(self.outline.GetOutputPort())

        #create outline actor
        self.outlineActor = vtk.vtkActor()
        self.outlineActor.SetMapper(self.outlineMapper)

        #add actors to parent render window
        self.parent.ren.AddActor(self.actor)
        self.parent.ren.AddActor(self.outlineActor)
def setup_renderer(renderer, actors, bboxpolydata=None):
    ren = renderer
    for actor in actors:
        # assign actor to the renderer
        ren.AddActor(actor)
    ############################################
    # Create a vtkOutlineFilter to draw the bounding box of the data set.
    # Also create the associated mapper and actor.
    if bboxpolydata is not None:
        outline = vtk.vtkOutlineFilter()
        outline.SetInput(bboxpolydata.GetOutput())
        mapOutline = vtk.vtkPolyDataMapper()
        mapOutline.SetInputConnection(outline.GetOutputPort())
        outlineActor = vtk.vtkActor()
        outlineActor.SetMapper(mapOutline)
        outlineActor.GetProperty().SetColor(100, 100, 100)
        ren.AddViewProp(outlineActor)
        ren.AddActor(outlineActor)
    

    # Create a vtkLight, and set the light parameters.
    light = vtk.vtkLight()
    light.SetFocalPoint(0.21406, 1.5, 0)
    light.SetPosition(8.3761, 4.94858, 4.12505)
    ren.AddLight(light)
    return ren
	def __init__(self, parent, visualizer, **kws):
		"""
		Initialization
		"""     
		self.x, self.y, self.z = -1, -1, -1
		VisualizationModule.__init__(self, parent, visualizer, **kws)
		self.on = 0
		self.renew = 1
		self.mapper = vtk.vtkPolyDataMapper()
		self.eventDesc = "Rendering orthogonal slices"
		self.outline = vtk.vtkOutlineFilter()
		self.outlineMapper = vtk.vtkPolyDataMapper()
		self.outlineActor = vtk.vtkActor()
		self.outlineActor.SetMapper(self.outlineMapper)
		
		self.picker = vtk.vtkCellPicker()
		self.picker.SetTolerance(0.005)
		
		self.planeWidgetX = vtk.vtkImagePlaneWidget()
		self.planeWidgetX.DisplayTextOn()
		self.planeWidgetX.SetPicker(self.picker)
		self.planeWidgetX.SetKeyPressActivationValue("x")
		#self.planeWidgetX.UserControlledLookupTableOn()
		self.prop1 = self.planeWidgetX.GetPlaneProperty()
		#self.prop1.SetColor(1, 0, 0)
		self.planeWidgetX.SetResliceInterpolateToCubic()

		self.planeWidgetY = vtk.vtkImagePlaneWidget()
		self.planeWidgetY.DisplayTextOn()
		self.planeWidgetY.SetPicker(self.picker)
		self.planeWidgetY.SetKeyPressActivationValue("y")
		self.prop2 = self.planeWidgetY.GetPlaneProperty()
		self.planeWidgetY.SetResliceInterpolateToCubic()
		#self.planeWidgetY.UserControlledLookupTableOn()
		#self.prop2.SetColor(1, 1, 0)


		# for the z-slice, turn off texture interpolation:
		# interpolation is now nearest neighbour, to demonstrate
		# cross-hair cursor snapping to pixel centers
		self.planeWidgetZ = vtk.vtkImagePlaneWidget()
		self.planeWidgetZ.DisplayTextOn()
		self.planeWidgetZ.SetPicker(self.picker)
		self.planeWidgetZ.SetKeyPressActivationValue("z")
		self.prop3 = self.planeWidgetZ.GetPlaneProperty()
		#self.prop3.SetColor(1, 0, 1)
		#self.planeWidgetZ.UserControlledLookupTableOn()
		self.planeWidgetZ.SetResliceInterpolateToCubic()
		self.renderer = self.parent.getRenderer()
		self.renderer.AddActor(self.outlineActor)
		self.useOutline = 1
		
		iactor = self.wxrenwin.GetRenderWindow().GetInteractor()
		self.planeWidgetX.SetInteractor(iactor)
		self.planeWidgetY.SetInteractor(iactor)
		self.planeWidgetZ.SetInteractor(iactor)
		
		lib.messenger.connect(None, "zslice_changed", self.setZ)
		self.filterDesc = "View orthogonal slices"
Exemplo n.º 22
0
def CreateRen1(slcr, cam, viewport, background):
    #Create BOne
    contourBone = vtk.vtkContourFilter()
    contourBone.SetInputConnection(slcr.GetOutputPort())
    contourBone.SetValue(0, 75.0)

    mapperBone = vtk.vtkPolyDataMapper()
    mapperBone.SetInputConnection(contourBone.GetOutputPort())
    mapperBone.SetScalarVisibility(0)

    # Create Outliner
    outliner = vtk.vtkOutlineFilter()
    outliner.SetInputConnection(slcr.GetOutputPort())
    outliner.Update()

    mapperOutliner = vtk.vtkPolyDataMapper()
    mapperOutliner.SetInputConnection(outliner.GetOutputPort())

    contourSkin = vtk.vtkContourFilter()
    contourSkin.SetInputConnection(slcr.GetOutputPort())
    contourSkin.SetValue(0, 50.0)

    # Create CutSkin
    plane = vtk.vtkPlane()
    plane.SetOrigin(0, 0, 0)
    plane.SetNormal(0, 0, 1)

    cutter = vtk.vtkCutter()
    cutter.SetCutFunction(plane)
    cutter.SetInputConnection(contourSkin.GetOutputPort())
    for i in range(100):
        cutter.SetValue(i, 10 * i)
    cutter.Update()

    mapperSkin = vtk.vtkPolyDataMapper()
    mapperSkin.SetInputConnection(cutter.GetOutputPort())
    mapperSkin.SetScalarVisibility(0)

    # Create Actor
    actorBone = vtk.vtkActor()
    actorBone.SetMapper(mapperBone)

    actorSkin = vtk.vtkActor()
    actorSkin.SetMapper(mapperSkin)
    actorSkin.GetProperty().SetColor(0.74, 0.55, 0.55)

    actorOutliner = vtk.vtkActor()
    actorOutliner.SetMapper(mapperOutliner)

    ren = vtk.vtkRenderer()
    ren.AddActor(actorBone)
    ren.AddActor(actorSkin)
    ren.AddActor(actorOutliner)
    ren.SetViewport(viewport)
    ren.SetActiveCamera(cam)
    ren.ResetCamera()
    ren.SetBackground(background)

    return ren
Exemplo n.º 23
0
def contour_G(filename):
    # Creating contour for G fileld

    data = vtk.vtkXMLImageDataReader()
    data.SetFileName(
        filename)  #"/Users/y1275963/Documents/homework/multifield.0060.vti")

    data_g = vtk.vtkAssignAttribute()
    data_g.SetInputConnection(data.GetOutputPort())
    data_g.Assign('G', 'SCALARS', 'POINT_DATA')

    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(data_g.GetOutputPort())

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

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

    # Create a filter to extract an isosurface from
    # the dataset.  Connect the input of this
    # filter to the output of the reader.  Set the
    # value for the (one) isosurface that we want
    # to extract, and tell the filter to compute
    # normal vectors for each triangle on the
    # output isosurface.

    iso = vtk.vtkContourFilter()
    iso.SetInputConnection(data_g.GetOutputPort())
    iso.ComputeNormalsOn()
    iso.SetNumberOfContours(1)
    iso.SetValue(0, 2500)  #Chnge here to change the isovalue

    # Create a mapper to traverse the polydata and
    # generate graphics commands for drawing the
    # polygons onto the output device.

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(iso.GetOutputPort())
    mapper.ScalarVisibilityOff()

    # Output primitives (i.e. the triangles making
    # up the isosurface) are managed as an actor;
    # we specify that all outputs are coloured
    # red.

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(1, 0, 0)
    actor.GetProperty().SetOpacity(0.5)

    # Create a renderer which will output the
    # graphics commands onto a drawing surface within
    # a window.  By default the renderer will fill
    # all of the window.  We set the background
    # colour of the window to white.
    return (outlineActor, actor)
    def __init__(self,reader):
		self.outline=vtk.vtkOutlineFilter()
		self.outline.SetInput(reader.get_data_set())
		self.outlinemapper=vtk.vtkPolyDataMapper()
		self.outlinemapper.SetInput(self.outline.GetOutput())
		self.actor=vtk.vtkActor()
		self.actor.SetMapper(self.outlinemapper)
		self.actor.GetProperty().SetColor(0,0,0)
Exemplo n.º 25
0
def outline(source):
    outline_filter = vtk.vtkOutlineFilter()
    outline_filter.SetInput(source.GetOutput())
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInput(outline_filter.GetOutput())
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    return actor
Exemplo n.º 26
0
 def __init__(self, reader):
     self.outline = vtk.vtkOutlineFilter()
     self.outline.SetInput(reader.get_data_set())
     self.outlinemapper = vtk.vtkPolyDataMapper()
     self.outlinemapper.SetInput(self.outline.GetOutput())
     self.actor = vtk.vtkActor()
     self.actor.SetMapper(self.outlinemapper)
     self.actor.GetProperty().SetColor(0, 0, 0)
Exemplo n.º 27
0
def create_box(source):
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(source.GetOutputPort())
    mapper = vtk.vtkDataSetMapper()
    mapper.SetInputConnection(outline.GetOutputPort())
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    return actor
Exemplo n.º 28
0
def visQuadFunc():
    """ vtk sample scene with iso contours """

    # VTK supports implicit functions of the form f(x,y,z)=constant. These
    # functions can represent things spheres, cones, etc. Here we use a
    # general form for a quadric to create an elliptical data field.
    quadric = vtk.vtkQuadric()
    quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0)

    # vtkSampleFunction samples an implicit function over the x-y-z range
    # specified (here it defaults to -1,1 in the x,y,z directions).
    sample = vtk.vtkSampleFunction()
    sample.SetSampleDimensions(30, 30, 30)
    sample.SetImplicitFunction(quadric)

    # Create five surfaces F(x,y,z) = constant between range specified. The
    # GenerateValues() method creates n isocontour values between the range
    # specified.
    contours = vtk.vtkContourFilter()
    contours.SetInputConnection(sample.GetOutputPort())
    contours.GenerateValues(8, 0.0, 1.2)

    contMapper = vtk.vtkPolyDataMapper()
    contMapper.SetInputConnection(contours.GetOutputPort())
    contMapper.SetScalarRange(0.0, 1.2)

    contActor = vtk.vtkActor()
    contActor.SetMapper(contMapper)

    # We'll put a simple outline around the data.
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(sample.GetOutputPort())

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

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

    # extract data from the volume
    extract = vtk.vtkExtractVOI()
    extract.SetInputConnection(sample.GetOutputPort())
    extract.SetVOI(0, 29, 0, 29, 15, 15)
    extract.SetSampleRate(1, 2, 3)

    contours2 = vtk.vtkContourFilter()
    contours2.SetInputConnection(extract.GetOutputPort())
    contours2.GenerateValues(8, 0.0, 1.2)

    contMapper2 = vtk.vtkPolyDataMapper()
    contMapper2.SetInputConnection(contours2.GetOutputPort())
    contMapper2.SetScalarRange(0.0, 1.2)

    contActor2 = vtk.vtkActor()
    contActor2.SetMapper(contMapper2)

    return contActor, contActor2, outlineActor, contours, contours2
Exemplo n.º 29
0
    def __init__(self, parent):
        QVTKRenderWindowInteractor.__init__(self, parent)

        self.renderer = vtk.vtkRenderer()
        self.GetRenderWindow().AddRenderer(self.renderer)
        
        interactor = vtk.vtkInteractorStyleSwitch()
        self._Iren.SetInteractorStyle(interactor)
                
        self.surface = None

        # Remainng calls set up axes.
        tprop = vtk.vtkTextProperty()
        tprop.SetColor(1,1,1)

        # Create a faint outline to go with the axes.
        self.outline = vtk.vtkOutlineFilter()

        # Initially set up with a box as input.  This will be changed
        # to a plot once the user clicks something.
        self.box = vtk.vtkBox()
        self.box.SetBounds(0,10,0,10,0,10)
        sample = vtk.vtkSampleFunction()
        sample.SetImplicitFunction(self.box)
        sample.SetSampleDimensions(2,2,2)
        sample.SetModelBounds(0,10,0,10,0,5)
        sample.ComputeNormalsOff()

        self.outline.SetInputConnection(sample.GetOutputPort())
        mapOutline = vtk.vtkPolyDataMapper()
        mapOutline.SetInputConnection(self.outline.GetOutputPort())
        self.outlineActor = vtk.vtkActor()
        self.outlineActor.SetMapper(mapOutline)
        self.outlineActor.GetProperty().SetColor(1,1,1)
        self.outlineActor.GetProperty().SetOpacity(.25)
        self.renderer.AddActor(self.outlineActor)

        self.axes = vtk.vtkCubeAxesActor2D()
        self.axes.SetCamera(self.renderer.GetActiveCamera())
        self.axes.SetFlyModeToOuterEdges()

        self.axes.SetLabelFormat("%6.4g")
        self.axes.SetFontFactor(0.8)
        self.axes.SetAxisTitleTextProperty(tprop)
        self.axes.SetAxisLabelTextProperty(tprop)
        self.axes.SetXLabel("MPI Rank")
        self.axes.SetYLabel("Progress")
        self.axes.SetZLabel("Effort")
        self.axes.SetInput(sample.GetOutput())
        self.renderer.AddViewProp(self.axes)

        # Keep original camera around in case it gets changed
        self.originalCamera = self.renderer.GetActiveCamera()

        self.renderer.GetActiveCamera().Pitch(90)     # Want effort to be vertical
        self.renderer.GetActiveCamera().OrthogonalizeViewUp()
        self.renderer.ResetCamera()
        self.renderer.GetActiveCamera().Elevation(15)  # Be slightly above the data
Exemplo n.º 30
0
def visQuadFunc():
    """ vtk sample scene with iso contours """

    # VTK supports implicit functions of the form f(x,y,z)=constant. These
    # functions can represent things spheres, cones, etc. Here we use a
    # general form for a quadric to create an elliptical data field.
    quadric = vtk.vtkQuadric()
    quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0)

    # vtkSampleFunction samples an implicit function over the x-y-z range
    # specified (here it defaults to -1,1 in the x,y,z directions).
    sample = vtk.vtkSampleFunction()
    sample.SetSampleDimensions(30, 30, 30)
    sample.SetImplicitFunction(quadric)

    # Create five surfaces F(x,y,z) = constant between range specified. The
    # GenerateValues() method creates n isocontour values between the range
    # specified.
    contours = vtk.vtkContourFilter()
    contours.SetInputConnection(sample.GetOutputPort())
    contours.GenerateValues(8, 0.0, 1.2)

    contMapper = vtk.vtkPolyDataMapper()
    contMapper.SetInputConnection(contours.GetOutputPort())
    contMapper.SetScalarRange(0.0, 1.2)

    contActor = vtk.vtkActor()
    contActor.SetMapper(contMapper)

    # We'll put a simple outline around the data.
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(sample.GetOutputPort())

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

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

    # extract data from the volume
    extract = vtk.vtkExtractVOI()
    extract.SetInputConnection(sample.GetOutputPort())
    extract.SetVOI(0, 29, 0, 29, 15, 15)
    extract.SetSampleRate(1, 2, 3)

    contours2 = vtk.vtkContourFilter()
    contours2.SetInputConnection(extract.GetOutputPort())
    contours2.GenerateValues(8, 0.0, 1.2)

    contMapper2 = vtk.vtkPolyDataMapper()
    contMapper2.SetInputConnection(contours2.GetOutputPort())
    contMapper2.SetScalarRange(0.0, 1.2)

    contActor2 = vtk.vtkActor()
    contActor2.SetMapper(contMapper2)

    return contActor, contActor2, outlineActor, contours, contours2
Exemplo n.º 31
0
def setVtkWidget(vtkWidget):

    colors = vtk.vtkNamedColors()

    # Create the RenderWindow, Renderer and Interactor.
    #

    ren1 = vtk.vtkRenderer()
    vtkWidget.GetRenderWindow().AddRenderer(ren1)

    iren = vtkWidget.GetRenderWindow().GetInteractor()

    reader = vtk.vtkMetaImageReader()
    reader.SetFileName('FullHead.mha')
    reader.Update()

    locator = vtk.vtkMergePoints()
    locator.SetDivisions(396, 396, 24)
    locator.SetNumberOfPointsPerBucket(1)
    locator.AutomaticOff()

    iso = vtk.vtkMarchingCubes()
    iso.SetInputConnection(reader.GetOutputPort())
    iso.ComputeGradientsOn()
    iso.ComputeScalarsOff()
    iso.SetValue(0, 1)
    iso.SetLocator(locator)

    isoMapper = vtk.vtkPolyDataMapper()
    isoMapper.SetInputConnection(iso.GetOutputPort())
    isoMapper.ScalarVisibilityOff()

    isoActor = vtk.vtkActor()
    isoActor.SetMapper(isoMapper)
    isoActor.GetProperty().SetColor(colors.GetColor3d("Wheat"))

    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(reader.GetOutputPort())

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

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

    # Add the actors to the renderer, set the background and size.
    #
    ren1.AddActor(outlineActor)
    ren1.AddActor(isoActor)
    ren1.SetBackground(colors.GetColor3d("Black"))
    ren1.GetActiveCamera().SetFocalPoint(0, 0, 0)
    ren1.GetActiveCamera().SetPosition(0, -1, 0)
    ren1.GetActiveCamera().SetViewUp(0, 0, -1)
    ren1.ResetCamera()
    ren1.GetActiveCamera().Dolly(1.5)
    ren1.ResetCameraClippingRange()

    iren.Initialize()
Exemplo n.º 32
0
    def __init__(self, parent, visualizer, **kws):
        """
		Initialization
		"""
        self.x, self.y, self.z = -1, -1, -1
        VisualizationModule.__init__(self, parent, visualizer, **kws)
        self.on = 0
        self.renew = 1
        self.mapper = vtk.vtkPolyDataMapper()
        self.eventDesc = "Rendering orthogonal slices"
        self.outline = vtk.vtkOutlineFilter()
        self.outlineMapper = vtk.vtkPolyDataMapper()
        self.outlineActor = vtk.vtkActor()
        self.outlineActor.SetMapper(self.outlineMapper)

        self.picker = vtk.vtkCellPicker()
        self.picker.SetTolerance(0.005)

        self.planeWidgetX = vtk.vtkImagePlaneWidget()
        self.planeWidgetX.DisplayTextOn()
        self.planeWidgetX.SetPicker(self.picker)
        self.planeWidgetX.SetKeyPressActivationValue("x")
        #self.planeWidgetX.UserControlledLookupTableOn()
        self.prop1 = self.planeWidgetX.GetPlaneProperty()
        #self.prop1.SetColor(1, 0, 0)
        self.planeWidgetX.SetResliceInterpolateToCubic()

        self.planeWidgetY = vtk.vtkImagePlaneWidget()
        self.planeWidgetY.DisplayTextOn()
        self.planeWidgetY.SetPicker(self.picker)
        self.planeWidgetY.SetKeyPressActivationValue("y")
        self.prop2 = self.planeWidgetY.GetPlaneProperty()
        self.planeWidgetY.SetResliceInterpolateToCubic()
        #self.planeWidgetY.UserControlledLookupTableOn()
        #self.prop2.SetColor(1, 1, 0)

        # for the z-slice, turn off texture interpolation:
        # interpolation is now nearest neighbour, to demonstrate
        # cross-hair cursor snapping to pixel centers
        self.planeWidgetZ = vtk.vtkImagePlaneWidget()
        self.planeWidgetZ.DisplayTextOn()
        self.planeWidgetZ.SetPicker(self.picker)
        self.planeWidgetZ.SetKeyPressActivationValue("z")
        self.prop3 = self.planeWidgetZ.GetPlaneProperty()
        #self.prop3.SetColor(1, 0, 1)
        #self.planeWidgetZ.UserControlledLookupTableOn()
        self.planeWidgetZ.SetResliceInterpolateToCubic()
        self.renderer = self.parent.getRenderer()
        self.renderer.AddActor(self.outlineActor)
        self.useOutline = 1

        iactor = self.wxrenwin.GetRenderWindow().GetInteractor()
        self.planeWidgetX.SetInteractor(iactor)
        self.planeWidgetY.SetInteractor(iactor)
        self.planeWidgetZ.SetInteractor(iactor)

        lib.messenger.connect(None, "zslice_changed", self.setZ)
        self.filterDesc = "View orthogonal slices"
Exemplo n.º 33
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkOutlineFilter(),
                                       'Processing.', ('vtkDataSet', ),
                                       ('vtkPolyData', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
Exemplo n.º 34
0
def new_outline_actor(node: vtk.vtkDataSet):
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(node.GetOutputPort())
    mapOutline = vtk.vtkPolyDataMapper()
    mapOutline.SetInputConnection(outline.GetOutputPort())
    outlineActor = vtk.vtkActor()
    outlineActor.SetMapper(mapOutline)
    outlineActor.GetProperty().SetColor(0, 0, 0)
    return outlineActor
Exemplo n.º 35
0
def main():
    fileName = get_program_parameters()

    colors = vtk.vtkNamedColors()

    # Create the RenderWindow, Renderer and Interactor.
    #

    ren1 = vtk.vtkRenderer()

    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren1)

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

    # Create the pipeline.
    #
    reader = vtk.vtkStructuredPointsReader()
    reader.SetFileName(fileName)

    iso = vtk.vtkContourFilter()
    iso.SetInputConnection(reader.GetOutputPort())
    iso.SetValue(0, 128)

    isoMapper = vtk.vtkPolyDataMapper()
    isoMapper.SetInputConnection(iso.GetOutputPort())
    isoMapper.ScalarVisibilityOff()

    isoActor = vtk.vtkActor()
    isoActor.SetMapper(isoMapper)
    isoActor.GetProperty().SetColor(colors.GetColor3d("Banana"))

    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(reader.GetOutputPort())

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

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

    # Add the actors to the renderer, set the background and size.
    #
    ren1.AddActor(outlineActor)
    ren1.AddActor(isoActor)
    ren1.SetBackground(colors.GetColor3d("SlateGray"))
    renWin.SetSize(640, 640)
    renWin.SetWindowName('IronIsoSurface')

    # Render the image.
    #
    ren1.ResetCamera()
    ren1.GetActiveCamera().Azimuth(30)
    ren1.GetActiveCamera().Elevation(30)
    renWin.Render()
    iren.Start()
def MakeBoundingBoxActor(polydata):
    
    bbFilter = vtk.vtkOutlineFilter()
    bbFilter.SetInputData(polydata)
    bbFilter.Update()

    actor = utils.MakeActor(bbFilter.GetOutput())

    return actor
Exemplo n.º 37
0
def createOutlineActor(image):
    outlineData = vtk.vtkOutlineFilter()
    outlineData.SetInput(image)
    mapOutline = vtk.vtkPolyDataMapper()
    mapOutline.SetInputConnection(outlineData.GetOutputPort())
    outline = vtk.vtkActor()
    outline.SetMapper(mapOutline)
    outline.GetProperty().SetColor(0, 0, 0)
    return outline
Exemplo n.º 38
0
def getBoundingBox(vtkData):
    boundingBoxFilter = vtk.vtkOutlineFilter()
    if vtk.VTK_MAJOR_VERSION <= 5:
        boundingBoxFilter.SetInput(vtkData)
    else:
        boundingBoxFilter.SetInputData(vtkData)
    boundingBoxFilter.Update()
    boundingBox = boundingBoxFilter.GetOutput()
    return boundingBox
Exemplo n.º 39
0
def isoFile(filename):
 
 reader = vtk.vtkStructuredPointsReader()
 reader.SetFileName(filename)
 reader.Update()

 iso = vtk.vtkMarchingCubes()
 iso.SetInput(reader.GetOutput())
 iso.SetValue(0,0.4)

# Set up mapper 
 poly_map = vtk.vtkPolyDataMapper()
 poly_map.SetInput(iso.GetOutput())

# Set up actor for iso surface rendering
 isoActor = vtk.vtkActor()
 isoActor.SetMapper(poly_map) 

# Define outline of the isosurface
 outline = vtk.vtkOutlineFilter()
 outline.SetInputConnection(reader.GetOutputPort())
 mapOutline = vtk.vtkPolyDataMapper()
 mapOutline.SetInputConnection(outline.GetOutputPort())
 outlineActor = vtk.vtkActor()
 outlineActor.SetMapper(mapOutline)
 outlineActor.GetProperty().SetColor(0, 0, 0)

# Set up the Back ground of iso surface 
 ren.SetBackground(1,1,1)

# Adding actors for rendering. If you want to see the outline of the isosurface then  please activate outlineactor here.
 ren.AddActor(outlineActor)  
 ren.AddActor(isoActor)
 
# Selecting renderer good position and focal point. If you want  you can change the camera positin for viewing your expected image. 
 
 ren.GetActiveCamera().SetPosition(0, 2,20)
 ren.GetActiveCamera().SetFocalPoint(-15,12,90)
 ren.GetActiveCamera().SetViewUp(180,10 ,-90 )

 ren.ResetCamera()
 ren.GetActiveCamera().Dolly(2.25)
 ren.ResetCameraClippingRange()
	
 largestreamline=vtk.vtkRenderLargeImage()
 largestreamline.SetInput(ren)
 
 largestreamline.SetMagnification(2)
 
# Writing .PNG Images of the streamlines with geometry
 writer = vtk.vtkPNGWriter()
 writer.SetInputConnection(largestreamline.GetOutputPort())
 writer.SetFileName("Streamline.png")
 writer.Modified()
 
 writer.Write()
Exemplo n.º 40
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()

        # Create source
        sphere = vtk.vtkSphere()

        # Sample the function
        sample = vtk.vtkSampleFunction()
        sample.SetSampleDimensions(50, 50, 50)
        sample.SetImplicitFunction(sphere)
        sample.SetModelBounds(-2, 2, -2, 2, -2, 2)

        # Create the 0 isosurface
        contours = vtk.vtkContourFilter()
        contours.SetInputConnection(sample.GetOutputPort())
        contours.GenerateValues(1, 1, 1)

        # Map the contours to graphical primitives
        contourMapper = vtk.vtkPolyDataMapper()
        contourMapper.SetInputConnection(contours.GetOutputPort())
        contourMapper.SetScalarRange(0, 1.2)

        # Create an actor for the contours
        contourActor = vtk.vtkActor()
        contourActor.SetMapper(contourMapper)

        # -- Create a box around the function to indicated the sampling volume

        # Create outline
        outline = vtk.vtkOutlineFilter()
        outline.SetInputConnection(sample.GetOutputPort())

        # Map it to graphics primitives
        outlineMapper = vtk.vtkPolyDataMapper()
        outlineMapper.SetInputConnection(outline.GetOutputPort())

        # Create an actor for it
        outlineActor = vtk.vtkActor()
        outlineActor.SetMapper(outlineMapper)
        outlineActor.GetProperty().SetColor(0, 0, 0)

        self.ren.AddActor(contourActor)
        self.ren.AddActor(outlineActor)
        self.ren.ResetCamera()

        self._initialized = False
Exemplo n.º 41
0
def main():
    InputFilename = get_program_parameters()

    colors = vtk.vtkNamedColors()

    # vtkSLCReader to read.
    reader = vtk.vtkSLCReader()
    reader.SetFileName(InputFilename)
    reader.Update()

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

    # Implementing Marching Cubes Algorithm to create the surface using vtkContourFilter object.
    contourFilter = vtk.vtkContourFilter()
    contourFilter.SetInputConnection(reader.GetOutputPort())
    contourFilter.SetValue(0, 72.0)

    outliner = vtk.vtkOutlineFilter()
    outliner.SetInputConnection(reader.GetOutputPort())
    outliner.Update()

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(contourFilter.GetOutputPort())
    mapper.SetScalarVisibility(0)

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

    # Create a rendering window and renderer.
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindow.SetSize(500, 500)

    # Create a renderwindowinteractor.
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

    # Assign actor to the renderer.
    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d("lemon_chiffon"))

    # Pick a good view
    renderer.GetActiveCamera().SetPosition(-382.606608, -3.308563, 223.475751)
    renderer.GetActiveCamera().SetFocalPoint(77.311562, 72.821162, 100.000000)
    renderer.GetActiveCamera().SetViewUp(0.235483, 0.137775, 0.962063)
    renderer.GetActiveCamera().SetDistance(482.25171)
    renderer.GetActiveCamera().SetClippingRange(27.933848, 677.669341)
    renderWindow.Render()

    # Enable user interface interactor.
    renderWindowInteractor.Initialize()
    renderWindow.Render()
    renderWindowInteractor.Start()
Exemplo n.º 42
0
def main():
    # source—filter——mapper——actor——render——renderwindow——interactor
    aRenderer = vtk.vtkRenderer()  # 渲染器

    renWin = vtk.vtkRenderWindow()  # 渲染窗口
    renWin.AddRenderer(aRenderer)

    v16 = vtk.vtkNIFTIImageReader()
    v16.SetFileName(file)
    v16.TimeAsVectorOn()
    v16.Update()

    skinExtractor = vtk.vtkContourFilter()
    skinExtractor.SetInputConnection(v16.GetOutputPort())
    skinExtractor.SetValue(0, 500)

    skinNormals = vtk.vtkPolyDataNormals()
    skinNormals.SetInputConnection(skinExtractor.GetOutputPort())
    skinNormals.SetFeatureAngle(60.0)

    skinMapper = vtk.vtkPolyDataMapper()  # 映射器
    skinMapper.SetInputConnection(skinNormals.GetOutputPort())
    skinMapper.ScalarVisibilityOff()

    skin = vtk.vtkActor()
    skin.SetMapper(skinMapper)

    outlineData = vtk.vtkOutlineFilter()
    outlineData.SetInputConnection(v16.GetOutputPort())
    mapOutline = vtk.vtkPolyDataMapper()
    mapOutline.SetInputConnection(outlineData.GetOutputPort())

    outline = vtk.vtkActor()
    outline.SetMapper(mapOutline)
    outline.GetProperty().SetColor(0, 0, 0)

    aCamera = vtk.vtkCamera()
    aCamera.SetViewUp(0, 0, -1)
    aCamera.SetPosition(0, 1, 0)
    aCamera.SetFocalPoint(0, 0, 0)
    aCamera.ComputeViewPlaneNormal()

    aRenderer.AddActor(outline)
    aRenderer.AddActor(skin)
    aRenderer.SetActiveCamera(aCamera)
    aRenderer.ResetCamera()
    aCamera.Dolly(1.5)

    aRenderer.SetBackground(1, 1, 1)
    renWin.SetSize(640, 480)
    aRenderer.ResetCameraClippingRange()

    iren = vtk.vtkRenderWindowInteractor()  # 窗口交互
    iren.SetRenderWindow(renWin)
    iren.Initialize()
    iren.Start()
Exemplo n.º 43
0
 def create_outline(self):
     outline = vtk.vtkOutlineFilter()
     outline.SetInputData(self.rdr.GetOutput())
     outline_mapper = vtk.vtkPolyDataMapper()
     outline_mapper.SetInputConnection(outline.GetOutputPort())
     self.outline_actor = vtk.vtkActor()
     self.outline_actor.SetMapper(outline_mapper)
     self.outline_actor.GetProperty().SetColor(1,1,1)
     self.outline = outline
     self.renderer.AddActor(self.outline_actor)
Exemplo n.º 44
0
    def prepareOutlineActor(self,_dim):
        outlineData = vtk.vtkImageData()
        outlineData.SetDimensions(_dim[0], _dim[1], 1)

        outline = vtk.vtkOutlineFilter()
        outline.SetInput(outlineData)
        outlineMapper = vtk.vtkPolyDataMapper()
        outlineMapper.SetInputConnection(outline.GetOutputPort())
    
        self.outlineActor.SetMapper(outlineMapper)
        self.outlineActor.GetProperty().SetColor(1, 1, 1)        
Exemplo n.º 45
0
    def addGrid(self, grid):
        nx, ny, nz = grid.shape[1:]

        self.display.append(True)

        self.grids.append(vtk.vtkStructuredGrid())

        self.grids[-1].SetExtent(0, nz-1, 0, ny-1, 0, nx-1)
        p = vtk.vtkPoints()

        shp = grid.shape
        grid.shape = (3, nx*ny*nz)
        p.SetData(vtknp.numpy_to_vtk(np.ascontiguousarray(grid.T), deep=True, array_type=vtknp.get_vtk_array_type(grid.dtype)))
        grid.shape = shp
        self.grids[-1].SetPoints(p)

        #Couleur
        color = np.random.rand(3)
        #Create a vtkOutlineFilter to draw the bounding box of the data set.
        ol = vtk.vtkOutlineFilter()
        if (vtk.vtkVersion().GetVTKMajorVersion()>=6):
          ol.SetInputData(self.grids[-1])
        else:
          ol.SetInput(self.grids[-1])      
        olm = vtk.vtkPolyDataMapper()
        olm.SetInputConnection(ol.GetOutputPort())
        ola = vtk.vtkActor()
        ola.SetMapper(olm)
        ola.GetProperty().SetColor(color)

        s=vtk.vtkShrinkFilter()
        if (vtk.vtkVersion().GetVTKMajorVersion()>=6):
          s.SetInputData(self.grids[-1])
        else:
          s.SetInput(self.grids[-1])      
        s.SetShrinkFactor(0.8)
        #
        mapper = vtk.vtkDataSetMapper()
        #map.SetInputData(data)
        mapper.SetInputConnection(s.GetOutputPort())
        act = vtk.vtkLODActor()
        act.SetMapper(mapper)
        #act.GetProperty().SetRepresentationToWireframe()
        #act.GetProperty().SetRepresentationToPoints()	
        act.GetProperty().SetColor(color)
        act.GetProperty().SetEdgeColor(color)
        act.GetProperty().EdgeVisibilityOff()	
        self.actors.append(act)
        self.setBounds()
        self.ren.SetActiveCamera(self.cam)
Exemplo n.º 46
0
 def __init__ (self, mod_m):
     debug ("In Outline::__init__ ()")
     Common.state.busy ()
     Base.Objects.Module.__init__ (self, mod_m)
     data_src = self.mod_m.get_data_source ()
     self.type = data_src.get_grid_type ()
     self.outline = vtk.vtkOutlineFilter ()
     self.outline.SetInput (mod_m.GetOutput ())
     self.mapper = self.map = vtk.vtkPolyDataMapper ()
     self.map.SetInput (self.outline.GetOutput ())
     self.actor = self.act = vtk.vtkActor ()  
     self.act.SetMapper (self.map)
     self.act.GetProperty ().SetColor (*Common.config.fg_color)
     self.renwin.add_actors (self.act)
     # used for the pipeline browser
     self.pipe_objs = self.act
     self.renwin.Render ()
     Common.state.idle ()
Exemplo n.º 47
0
    def prepareOutlineActor(self,_imageData):
#        print MODULENAME, '------------  prepareOutlineActor()'
        outlineDimTmp=_imageData.GetDimensions()
        # print "\n\n\n this is outlineDimTmp=",outlineDimTmp," self.outlineDim=",self.outlineDim
        if self.outlineDim[0] != outlineDimTmp[0] or self.outlineDim[1] != outlineDimTmp[1] or self.outlineDim[2] != outlineDimTmp[2]:
            self.outlineDim=outlineDimTmp
        
            outline = vtk.vtkOutlineFilter()
            outline.SetInput(_imageData)
            outlineMapper = vtk.vtkPolyDataMapper()
            outlineMapper.SetInputConnection(outline.GetOutputPort())
        
            self.outlineActor.SetMapper(outlineMapper)
            
            color = Configuration.getSetting("WindowColor")   # eventually do this smarter (only get/update when it changes)
            self.outlineActor.GetProperty().SetColor(float(color.red())/255,float(color.green())/255,float(color.blue())/255)
#            self.outlineActor.GetProperty().SetColor(1, 1, 1)        
            self.outlineDim = _imageData.GetDimensions()
Exemplo n.º 48
0
  def SetInput(self, input) :
    import itk
    img = itk.output(input)
    self.__input__ = img
    if img :
      # Update to try to avoid to exit if a c++ exception is throwed
      # sadely, it will not prevent the program to exit later...
      # a real fix would be to wrap c++ exception in vtk
      img.UpdateOutputInformation()
      img.Update()
      
      # flip the image to get the same representation than the vtk one
      self.__flipper__ = itk.FlipImageFilter[img].New(Input=img)
      axes = self.__flipper__.GetFlipAxes()
      axes.SetElement(1, True)
      self.__flipper__.SetFlipAxes(axes)
      
      # change the spacing while still keeping the ratio to workaround vtk bug
      # when spacing is very small
      spacing_ = itk.spacing(img)
      normSpacing = []
      for i in range(0, spacing_.Size()):
        normSpacing.append( spacing_.GetElement(i) / spacing_.GetElement(0) )
      self.__changeInfo__ = itk.ChangeInformationImageFilter[img].New(self.__flipper__, OutputSpacing=normSpacing, ChangeSpacing=True)
      
      # now really convert the data
      self.__itkvtkConverter__ = itk.ImageToVTKImageFilter[img].New(self.__changeInfo__)
      self.__volumeMapper__.SetInput(self.__itkvtkConverter__.GetOutput())
      # needed to avoid warnings
      # self.__itkvtkConverter__.GetOutput() must be callable
      
      import vtk
      if not self.__outline__ :
	  self.__outline__ = vtk.vtkOutlineFilter()
	  self.__outline__.SetInput(self.__itkvtkConverter__.GetOutput())
	  self.__outlineMapper__ = vtk.vtkPolyDataMapper()
	  self.__outlineMapper__.SetInput(self.__outline__.GetOutput())
	  self.__outlineActor__ = vtk.vtkActor()
	  self.__outlineActor__.SetMapper(self.__outlineMapper__)
	  self.__ren__.AddActor(self.__outlineActor__)
      else :
	  self.__outline__.SetInput(self.__itkvtkConverter__.GetOutput())

    self.Render()
Exemplo n.º 49
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()
 
        # Create source
        source = vtk.vtkConeSource()
        source.SetHeight(3.0)
        source.SetRadius(1.0)
        source.SetResolution(20)
 
        # Create a mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(source.GetOutputPort())
 
        # Create an actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)

        self.ren.AddActor(actor)

        # outline
        outline = vtk.vtkOutlineFilter()
        outline.SetInputConnection(source.GetOutputPort())
        mapper2 = vtk.vtkPolyDataMapper()
        mapper2.SetInputConnection(outline.GetOutputPort())
        actor2 = vtk.vtkActor()
        actor2.SetMapper(mapper2)
        self.ren.AddActor(actor2)
 
        self.ren.ResetCamera()

        self._initialized = False
Exemplo n.º 50
0
def create_renderer():
    """
    vtk renderer with a sample scene
    """
    quadric = vtk.vtkQuadric()
    quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0)

    sample = vtk.vtkSampleFunction()
    sample.SetSampleDimensions(50, 50, 50)
    sample.SetImplicitFunction(quadric)

    contours = vtk.vtkContourFilter()
    contours.SetInputConnection(sample.GetOutputPort())
    contours.GenerateValues(5, 0.0, 1.2)

    contour_mapper = vtk.vtkPolyDataMapper()
    contour_mapper.SetInputConnection(contours.GetOutputPort())
    contour_mapper.SetScalarRange(0.0, 1.2)

    contour_actor = vtk.vtkActor()
    contour_actor.SetMapper(contour_mapper)

    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(sample.GetOutputPort())

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

    outline_actor = vtk.vtkActor()
    outline_actor.SetMapper(outline_mapper)
    outline_actor.GetProperty().SetColor(0, 0, 0)

    renderer = vtk.vtkRenderer()
    renderer.AddActor(contour_actor)
    renderer.AddActor(outline_actor)
    renderer.SetBackground(.75, .75, .75)

    return renderer
Exemplo n.º 51
0
 def SetInput( self, Input ):
   import vtk
   if "GetOutput" in dir(Input):
     self.inputFilter = Input
     self.inputFilter.AddObserver('EndEvent', self.Update)
     self.input = Input.GetOutput()
   else:
     self.inputFilter = None
     self.input = Input
     
   self.volumeMapper.SetInput( self.input )
   if not self.outline :
       self.outline = vtk.vtkOutlineFilter()
       self.outline.SetInput( self.input )
       self.outlineMapper = vtk.vtkPolyDataMapper()
       self.outlineMapper.SetInput( self.outline.GetOutput() )
       self.outlineActor = vtk.vtkActor()
       self.outlineActor.SetMapper( self.outlineMapper )
       self.renderer.AddActor( self.outlineActor )
   else :
       self.outline.SetInput( self.input )
       
   self.colorAndOpacityEditor.SetInput( self.input )
Exemplo n.º 52
0
def vtk_render_window(iso, img=None, color=[0.5,0.5,0.5]):
    normals = vtk.vtkPolyDataNormals()
    normals.SetInputConnection(iso.GetOutputPort())
    normals.FlipNormalsOn()
    isoMapper = vtk.vtkPolyDataMapper()
    isoMapper.SetInput(normals.GetOutput())
    isoMapper.ScalarVisibilityOff()

    isoActor = vtk.vtkActor()
    isoActor.SetMapper(isoMapper)
    isoActor.GetProperty().SetColor(color)

    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Add the actors to the renderer, set the background and size
    if img!=None:
        outline = vtk.vtkOutlineFilter()
        outline.SetInput(img.GetOutput())
        outlineMapper = vtk.vtkPolyDataMapper()
        outlineMapper.SetInput(outline.GetOutput())
        outlineActor = vtk.vtkActor()
        outlineActor.SetMapper(outlineMapper)
        outlineActor.VisibilityOff()
        ren.AddActor(outlineActor)

    ren.AddActor(isoActor)
    ren.SetBackground(1.0,1.0,1.0)
    renWin.SetSize(450,450)
    ## ren.GetActiveCamera().Elevation(235)
    ## ren.GetActiveCamera().SetViewUp(0,.5,-1)
    ## ren.GetActiveCamera().Azimuth(90)
    iren.Initialize()
    return iren
Exemplo n.º 53
0
    def init_outline_actors(self, actor_specs, drawing_params=None):
        """
        Initializes outline actors for hex actors
        :param actor_specs: {ActorSpecs}
        :param drawing_params: {DrawingParameters}
        :return: None
        """
        actors_dict = actor_specs.actors_dict
        field_dim = self.currentDrawingParameters.bsd.fieldDim
        scene_metadata = drawing_params.screenshot_data.metadata
        mdata = MetadataHandler(mdata=scene_metadata)

        outline_data = vtk.vtkImageData()

        outline_data.SetDimensions(field_dim.x + 1, field_dim.y + 1, field_dim.z + 1)

        outline = vtk.vtkOutlineFilter()

        if VTK_MAJOR_VERSION >= 6:
            outline.SetInputData(outline_data)
        else:
            outline.SetInput(outline_data)

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

        outline_actor = actors_dict['outline_actor']

        outline_actor.SetMapper(outline_mapper)

        # lattice_type_str = self.get_lattice_type_str()
        # if lattice_type_str.lower() == 'hexagonal':
        if self.is_lattice_hex(drawing_params=drawing_params):
            outline_actor.SetScale(self.xScaleHex, self.yScaleHex, self.zScaleHex)

        outline_color = to_vtk_rgb(mdata.get('BoundingBoxColor',data_type='color'))
        outline_actor.GetProperty().SetColor(*outline_color)
Exemplo n.º 54
0
ellipNormals.SetInputConnection(ellipsoids.GetOutputPort())
# Map contour
lut = vtk.vtkLogLookupTable()
lut.SetHueRange(.6667,0.0)
ellipMapper = vtk.vtkPolyDataMapper()
ellipMapper.SetInputConnection(ellipNormals.GetOutputPort())
ellipMapper.SetLookupTable(lut)
plane.Update()
#force update for scalar range
ellipMapper.SetScalarRange(plane.GetOutput().GetScalarRange())
ellipActor = vtk.vtkActor()
ellipActor.SetMapper(ellipMapper)
#
# Create outline around data
#
outline = vtk.vtkOutlineFilter()
outline.SetInputConnection(ptLoad.GetOutputPort())
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInputConnection(outline.GetOutputPort())
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)
outlineActor.GetProperty().SetColor(0,0,0)
#
# Create cone indicating application of load
#
coneSrc = vtk.vtkConeSource()
coneSrc.SetRadius(.5)
coneSrc.SetHeight(2)
coneMap = vtk.vtkPolyDataMapper()
coneMap.SetInputConnection(coneSrc.GetOutputPort())
coneActor = vtk.vtkActor()
Exemplo n.º 55
0
skinExtractor.SetValue(0,500)
skinNormals = vtk.vtkPolyDataNormals()
skinNormals.SetInputConnection(skinExtractor.GetOutputPort())
skinNormals.SetFeatureAngle(60.0)
skinMapper = vtk.vtkPolyDataMapper()
skinMapper.SetInputConnection(skinNormals.GetOutputPort())
skinMapper.ScalarVisibilityOff()
skin = vtk.vtkActor()
skin.SetPosition(400, 200, 400)
skin.SetOrientation(270, 0, 180)
skin.SetMapper(skinMapper)
skin.GetProperty().SetDiffuseColor(1, .6, .25)
skin.GetProperty().SetOpacity(0.25)

#Create outline to show extent of the data.
outlineData = vtk.vtkOutlineFilter()
outlineData.SetInputConnection(v16.GetOutputPort())
mapOutline = vtk.vtkPolyDataMapper()
mapOutline.SetInputConnection(outlineData.GetOutputPort())
outline = vtk.vtkActor()
outline.SetPosition(400, 200, 400)
outline.SetOrientation(270, 0, 180)
outline.SetMapper(mapOutline)
outline.GetProperty().SetColor(0, 0, 0)

#Add actors to the renderer
aRenderer.AddActor(outline)
aRenderer.AddActor(contour)
aRenderer.AddActor(skin)

# Camera (viewpoint) settings
Exemplo n.º 56
0
    def testImagePlaneWidget(self):
        "A more rigorous test using the image plane widget."
        # This test is largely copied from
        # Widgets/Python/TestImagePlaneWidget.py

        # Load some data.
        v16 = vtk.vtkVolume16Reader()
        v16.SetDataDimensions(64, 64)
        v16.SetDataByteOrderToLittleEndian()
        v16.SetFilePrefix(os.path.join(VTK_DATA_ROOT, "Data", "headsq", "quarter"))
        v16.SetImageRange(1, 93)
        v16.SetDataSpacing(3.2, 3.2, 1.5)
        v16.Update()

        xMin, xMax, yMin, yMax, zMin, zMax = v16.GetExecutive().GetWholeExtent(v16.GetOutputInformation(0))
        img_data = v16.GetOutput()
        spacing = img_data.GetSpacing()
        sx, sy, sz = spacing

        origin = img_data.GetOrigin()
        ox, oy, oz = origin

        # An outline is shown for context.
        outline = vtk.vtkOutlineFilter()
        outline.SetInputData(img_data)

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

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

        # The shared picker enables us to use 3 planes at one time
        # and gets the picking order right
        picker = vtk.vtkCellPicker()
        picker.SetTolerance(0.005)

        # The 3 image plane widgets are used to probe the dataset.
        planeWidgetX = vtk.vtkImagePlaneWidget()
        planeWidgetX.DisplayTextOn()
        planeWidgetX.SetInputData(img_data)
        planeWidgetX.SetPlaneOrientationToXAxes()
        planeWidgetX.SetSliceIndex(32)
        planeWidgetX.SetPicker(picker)
        planeWidgetX.SetKeyPressActivationValue("x")
        prop1 = planeWidgetX.GetPlaneProperty()
        prop1.SetColor(1, 0, 0)

        planeWidgetY = vtk.vtkImagePlaneWidget()
        planeWidgetY.DisplayTextOn()
        planeWidgetY.SetInputData(img_data)
        planeWidgetY.SetPlaneOrientationToYAxes()
        planeWidgetY.SetSliceIndex(32)
        planeWidgetY.SetPicker(picker)
        planeWidgetY.SetKeyPressActivationValue("y")
        prop2 = planeWidgetY.GetPlaneProperty()
        prop2.SetColor(1, 1, 0)
        planeWidgetY.SetLookupTable(planeWidgetX.GetLookupTable())

        # for the z-slice, turn off texture interpolation:
        # interpolation is now nearest neighbour, to demonstrate
        # cross-hair cursor snapping to pixel centers
        planeWidgetZ = vtk.vtkImagePlaneWidget()
        planeWidgetZ.DisplayTextOn()
        planeWidgetZ.SetInputData(img_data)
        planeWidgetZ.SetPlaneOrientationToZAxes()
        planeWidgetZ.SetSliceIndex(46)
        planeWidgetZ.SetPicker(picker)
        planeWidgetZ.SetKeyPressActivationValue("z")
        prop3 = planeWidgetZ.GetPlaneProperty()
        prop3.SetColor(0, 0, 1)
        planeWidgetZ.SetLookupTable(planeWidgetX.GetLookupTable())

        # Now create another actor with an opacity < 1 and with some
        # scalars.
        p = vtk.vtkPolyData()
        pts = vtk.vtkPoints()
        pts.InsertNextPoint((0, 0, 0))
        sc = vtk.vtkFloatArray()
        sc.InsertNextValue(1.0)
        p.SetPoints(pts)
        p.GetPointData().SetScalars(sc)
        m = vtk.vtkPolyDataMapper()
        m.SetInputData(p)
        # Share the lookup table of the widgets.
        m.SetLookupTable(planeWidgetX.GetLookupTable())
        m.UseLookupTableScalarRangeOn()
        dummyActor = vtk.vtkActor()
        dummyActor.SetMapper(m)
        dummyActor.GetProperty().SetOpacity(0.0)

        # Create the RenderWindow and Renderer
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.SetMultiSamples(0)
        renWin.AddRenderer(ren)

        # Add the dummy actor.
        ren.AddActor(dummyActor)
        # Add the outline actor to the renderer, set the background
        # color and size
        ren.AddActor(outlineActor)
        renWin.SetSize(600, 600)
        ren.SetBackground(0.1, 0.1, 0.2)

        current_widget = planeWidgetZ
        mode_widget = planeWidgetZ

        # Set the interactor for the widgets
        iact = vtk.vtkRenderWindowInteractor()
        iact.SetRenderWindow(renWin)
        planeWidgetX.SetInteractor(iact)
        planeWidgetX.On()
        planeWidgetY.SetInteractor(iact)
        planeWidgetY.On()
        planeWidgetZ.SetInteractor(iact)
        planeWidgetZ.On()

        # Create an initial interesting view
        ren.ResetCamera()
        cam1 = ren.GetActiveCamera()
        cam1.Elevation(110)
        cam1.SetViewUp(0, 0, -1)
        cam1.Azimuth(45)
        ren.ResetCameraClippingRange()

        iact.Initialize()
        renWin.Render()
Exemplo 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()
Exemplo n.º 58
0
    def testimageMCAll(self):

        # Create the RenderWindow, Renderer and both Actors
        #
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)

        # create pipeline
        #
        slc = vtk.vtkStructuredPointsReader()
        slc.SetFileName(VTK_DATA_ROOT + "/Data/ironProt.vtk")

        colors = ["flesh", "banana", "grey", "pink", "carrot", "gainsboro", "tomato", "gold", "thistle", "chocolate"]

        types = ["UnsignedChar", "Char", "Short", "UnsignedShort", "Int", "UnsignedInt", "Long", "UnsignedLong", "Float", "Double"]

        i = 1
        c = 0
        clip = list()
        cast = list()
        iso = list()
        mapper = list()
        actor = list()

        colorWrapper = self.Colors()

        for idx, vtkType in enumerate(types):
            clip.append(vtk.vtkImageClip())
            clip[idx].SetInputConnection(slc.GetOutputPort())
            clip[idx].SetOutputWholeExtent(-1000, 1000, -1000, 1000, i, i + 5)
            i += 5
            cast.append(vtk.vtkImageCast())
            eval('cast[idx].SetOutputScalarTypeTo' + vtkType + '()')
            cast[idx].SetInputConnection(clip[idx].GetOutputPort())
            cast[idx].ClampOverflowOn()

            iso.append(vtk.vtkMarchingContourFilter())
            iso[idx].SetInputConnection(cast[idx].GetOutputPort())
            iso[idx].GenerateValues(1, 30, 30)

            mapper.append(vtk.vtkPolyDataMapper())
            mapper[idx].SetInputConnection(iso[idx].GetOutputPort())
            mapper[idx].ScalarVisibilityOff()

            actor.append(vtk.vtkActor())
            actor[idx].SetMapper(mapper[idx])
        #    actor[idx].Actor.GetProperty().SetDiffuseColor(lindex.colors.c.lindex.colors.c+1.lindex.colors.c+1)
            actor[idx].GetProperty().SetDiffuseColor(colorWrapper.GetRGBColor(colors[c]))
            actor[idx].GetProperty().SetSpecularPower(30)
            actor[idx].GetProperty().SetDiffuse(.7)
            actor[idx].GetProperty().SetSpecular(.5)
            c += 1
            ren.AddActor(actor[idx])


        outline = vtk.vtkOutlineFilter()
        outline.SetInputConnection(slc.GetOutputPort())
        outlineMapper = vtk.vtkPolyDataMapper()
        outlineMapper.SetInputConnection(outline.GetOutputPort())
        outlineActor = vtk.vtkActor()
        outlineActor.SetMapper(outlineMapper)
        outlineActor.VisibilityOff()

        # Add the actors to the renderer, set the background and size
        #
        ren.AddActor(outlineActor)
        ren.SetBackground(0.9, .9, .9)
        ren.ResetCamera()
        ren.GetActiveCamera().SetViewAngle(30)
        ren.GetActiveCamera().Elevation(20)
        ren.GetActiveCamera().Azimuth(20)
        ren.GetActiveCamera().Zoom(1.5)
        ren.ResetCameraClippingRange()

        renWin.SetSize(400, 400)

        # render and interact with data

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

        img_file = "imageMCAll.png"
        vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)
        vtk.test.Testing.interact()
    def testBug(self):
        # Uncomment the next line if you want to run this via
        # `gdb python`.
        #raw_input('Hit Ctrl-C')

        # Load some data.
        v16 = vtk.vtkVolume16Reader()
        v16.SetDataDimensions(64, 64)
        v16.SetDataByteOrderToLittleEndian()
        v16.SetFilePrefix(os.path.join(Testing.VTK_DATA_ROOT,
                                       "Data", "headsq", "quarter"))
        v16.SetImageRange(1, 93)
        v16.SetDataSpacing(3.2, 3.2, 1.5)
        v16.Update()

        xMin, xMax, yMin, yMax, zMin, zMax = v16.GetOutput().GetWholeExtent()
        img_data = v16.GetOutput()

        # **************************************************
        # Look here for wierdness.

        # Lets create this data using the data from the reader.
        my_img_data = vtk.vtkImageData()
        my_img_data.SetDimensions(img_data.GetDimensions())
        my_img_data.SetWholeExtent(img_data.GetWholeExtent())
        my_img_data.SetExtent(img_data.GetExtent())
        my_img_data.SetUpdateExtent(img_data.GetUpdateExtent())
        my_img_data.SetSpacing(img_data.GetSpacing())
        my_img_data.SetOrigin(img_data.GetOrigin())
        my_img_data.SetScalarType(img_data.GetScalarType())
        my_img_data.GetPointData().SetScalars(img_data.GetPointData().GetScalars())
        my_img_data.Update()
        # hang on to original image data.
        orig_img_data = img_data

        # hijack img_data with our own.  If you comment this out everything is
        # fine.
        img_data = my_img_data
        # **************************************************

        spacing = img_data.GetSpacing()
        sx, sy, sz = spacing

        origin = img_data.GetOrigin()
        ox, oy, oz = origin

        # An outline is shown for context.
        outline = vtk.vtkOutlineFilter()
        outline.SetInput(img_data)

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

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

        # The shared picker enables us to use 3 planes at one time
        # and gets the picking order right
        picker = vtk.vtkCellPicker()
        picker.SetTolerance(0.005)

        # The 3 image plane widgets are used to probe the dataset.
        planeWidgetX = vtk.vtkImagePlaneWidget()
        planeWidgetX.DisplayTextOn()
        planeWidgetX.SetInput(img_data)
        planeWidgetX.SetPlaneOrientationToXAxes()
        planeWidgetX.SetSliceIndex(32)
        planeWidgetX.SetPicker(picker)
        planeWidgetX.SetKeyPressActivationValue("x")
        prop1 = planeWidgetX.GetPlaneProperty()
        prop1.SetColor(1, 0, 0)

        planeWidgetY = vtk.vtkImagePlaneWidget()
        planeWidgetY.DisplayTextOn()
        planeWidgetY.SetInput(img_data)
        planeWidgetY.SetPlaneOrientationToYAxes()
        planeWidgetY.SetSliceIndex(32)
        planeWidgetY.SetPicker(picker)
        planeWidgetY.SetKeyPressActivationValue("y")
        prop2 = planeWidgetY.GetPlaneProperty()
        prop2.SetColor(1, 1, 0)
        planeWidgetY.SetLookupTable(planeWidgetX.GetLookupTable())

        # for the z-slice, turn off texture interpolation:
        # interpolation is now nearest neighbour, to demonstrate
        # cross-hair cursor snapping to pixel centers
        planeWidgetZ = vtk.vtkImagePlaneWidget()
        planeWidgetZ.DisplayTextOn()
        planeWidgetZ.SetInput(img_data)
        planeWidgetZ.SetPlaneOrientationToZAxes()
        planeWidgetZ.SetSliceIndex(46)
        planeWidgetZ.SetPicker(picker)
        planeWidgetZ.SetKeyPressActivationValue("z")
        prop3 = planeWidgetZ.GetPlaneProperty()
        prop3.SetColor(0, 0, 1)
        planeWidgetZ.SetLookupTable(planeWidgetX.GetLookupTable())

        # Create the RenderWindow and Renderer
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)

        # Add the outline actor to the renderer, set the background
        # color and size
        ren.AddActor(outlineActor)
        renWin.SetSize(600, 600)
        ren.SetBackground(0.1, 0.1, 0.2)

        current_widget = planeWidgetZ
        mode_widget = planeWidgetZ

        # Set the interactor for the widgets
        iact = vtk.vtkRenderWindowInteractor()
        iact.SetRenderWindow(renWin)
        planeWidgetX.SetInteractor(iact)
        planeWidgetX.On()
        planeWidgetY.SetInteractor(iact)
        planeWidgetY.On()
        planeWidgetZ.SetInteractor(iact)
        planeWidgetZ.On()

        # Create an initial interesting view
        ren.ResetCamera();
        cam1 = ren.GetActiveCamera()
        cam1.Elevation(110)
        cam1.SetViewUp(0, 0, -1)
        cam1.Azimuth(45)
        ren.ResetCameraClippingRange()

        iact.Initialize()
        renWin.Render()

        # Compare the images and test.
        img_file = "TestImagePlaneWidget.png"
        Testing.compareImage(renWin, Testing.getAbsImagePath(img_file))
        # Interact if necessary.
        if Testing.isInteractive():
            iact.Start()