コード例 #1
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkGaussianSplatter(), 'Processing.',
         ('vtkDataSet',), ('vtkImageData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
コード例 #2
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkGaussianSplatter(),
                                       'Processing.', ('vtkDataSet', ),
                                       ('vtkImageData', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
コード例 #3
0
ファイル: blog.py プロジェクト: zhenhaochu/pyNastran
def run_source():
    """https://www.creatis.insa-lyon.fr/~davila/bbtk/Software/new/doc/VTK_Documentation/report-about-vtk-2007-02.pdf"""
    pointSource = get_point_source()
    popSplatter = vtk.vtkGaussianSplatter()  # Splatter :
    popSplatter.SetSampleDimensions(300, 300, 300)  # points -> gauss sphere

    popSplatter.SetInputConnection(pointSource.GetOutputPort())
    # f(x) = scale * exp ( expF *(( r/ Radius )^2) )
    popSplatter.SetRadius(0.1)
    popSplatter.SetExponentFactor(1.0)
    popSplatter.SetScaleFactor(1.0)

    cast = vtk.vtkImageCast()  # uchar conversion
    cast.SetInputConnection(
        popSplatter.GetOutputPort())  # ( required by VRayCast )
    cast.SetOutputScalarTypeToUnsignedChar()

    alphaTF = vtk.vtkPiecewiseFunction()  # Opacity (A-TF)
    alphaTF.AddPoint(0, 0)
    alphaTF.AddPoint(1, 0.01)
    alphaTF.AddPoint(255, 0.5)
    colorTF = vtk.vtkColorTransferFunction()  # Color (RGB -TF)
    colorTF.AddRGBPoint(0, 1, 0.4, 0)
    colorTF.AddRGBPoint(255, 1, 0.0, 0)

    volumeProperty = vtk.vtkVolumeProperty()  # Property
    volumeProperty.SetColor(colorTF)
    volumeProperty.SetScalarOpacity(alphaTF)
    volumeProperty.SetInterpolationTypeToLinear()
    #compositeFunction = vtkVolumeRayCastCompositeFunction()# Mapper

    volumeMapper = vtk.vtkFixedPointVolumeRayCastMapper()  # ( Software )
    #volumeMapper.SetVolumeRayCastFunction(compositeFunction)
    volumeMapper.SetBlendModeToComposite()
    volumeMapper.SetInputConnection(cast.GetOutputPort())

    volume = vtk.vtkVolume()  # Volume = Mapper + Property
    volume.SetMapper(volumeMapper)
    volume.SetProperty(volumeProperty)

    ren = vtk.vtkRenderer()  # Renderer
    ren.AddVolume(volume)
    ren.ResetCamera()
    ren.GetActiveCamera().ParallelProjectionOn()

    renwin = vtk.vtkRenderWindow()  # Window
    renwin.AddRenderer(ren)
    renwin.SetSize(300, 300)
    renwin.SetDesiredUpdateRate(1.0)

    iren = vtk.vtkRenderWindowInteractor()  # Interactor
    iren.SetRenderWindow(renwin)
    iren.Start()
コード例 #4
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
        sphereSource = vtk.vtkSphereSource()
        sphereSource.Update()

        polydata = vtk.vtkPolyData()
        polydata.SetPoints(sphereSource.GetOutput().GetPoints())

        splatter = vtk.vtkGaussianSplatter()
        splatter.SetInput(polydata)
        splatter.SetSampleDimensions(50, 50, 50)
        splatter.SetRadius(0.05)
        splatter.ScalarWarpingOff()

        surface = vtk.vtkContourFilter()
        surface.SetInputConnection(splatter.GetOutputPort())
        surface.SetValue(0, 0.01)
 
        # Create a mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(surface.GetOutputPort())
 
        # Create an actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
 
        self.ren.AddActor(actor)
        self.ren.ResetCamera()

        self._initialized = False
コード例 #5
0
    def __init__(self, parent=None):
        super(VTKFrame, self).__init__(parent)

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

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

        # Create source
        sphereSource = vtk.vtkSphereSource()
        sphereSource.Update()

        polydata = vtk.vtkPolyData()
        polydata.SetPoints(sphereSource.GetOutput().GetPoints())

        splatter = vtk.vtkGaussianSplatter()
        splatter.SetInput(polydata)
        splatter.SetSampleDimensions(50, 50, 50)
        splatter.SetRadius(0.05)
        splatter.ScalarWarpingOff()

        surface = vtk.vtkContourFilter()
        surface.SetInputConnection(splatter.GetOutputPort())
        surface.SetValue(0, 0.01)

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

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

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

        self._initialized = False
コード例 #6
0
def main():
    # Create points on a sphere
    sphereSource = vtk.vtkSphereSource()
    sphereSource.Update()

    colors = vtk.vtkNamedColors()

    polydata = vtk.vtkPolyData()
    polydata.SetPoints(sphereSource.GetOutput().GetPoints())

    splatter = vtk.vtkGaussianSplatter()
    splatter.SetInputData(polydata)
    splatter.SetSampleDimensions(50, 50, 50)
    splatter.SetRadius(0.5)
    splatter.ScalarWarpingOff()

    surface = vtk.vtkContourFilter()
    surface.SetInputConnection(splatter.GetOutputPort())
    surface.SetValue(0, 0.01)

    # Create a mapper and actor
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(surface.GetOutputPort())

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

    # Visualize
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

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

    renderWindow.SetWindowName('GaussianSplat')
    renderWindow.Render()
    renderWindowInteractor.Start()
コード例 #7
0
# represent the array scalar (TIME_LATE)
calc.AddScalarVariable("s", scalar, 0)
# Divide scalar by max (applies division to all components of the array)
calc.SetFunction("s / %f"%max)
# The output array will be called resArray
calc.SetResultArrayName("resArray")

# Use AssignAttribute to make resArray the active scalar field
aa = vtk.vtkAssignAttribute()
aa.SetInputConnection(calc.GetOutputPort())
aa.Assign("resArray", "SCALARS", "POINT_DATA")
aa.Update()

# construct pipeline for original population
# GaussianSplatter -> Contour -> Mapper -> Actor
popSplatter = vtk.vtkGaussianSplatter()
popSplatter.SetInputConnection(aa.GetOutputPort())
popSplatter.SetSampleDimensions(50, 50, 50)
popSplatter.SetRadius(0.05)
popSplatter.ScalarWarpingOff()

popSurface = vtk.vtkContourFilter()
popSurface.SetInputConnection(popSplatter.GetOutputPort())
popSurface.SetValue(0, 0.01)

popMapper = vtk.vtkPolyDataMapper()
popMapper.SetInputConnection(popSurface.GetOutputPort())
popMapper.ScalarVisibilityOff()

popActor = vtk.vtkActor()
popActor.SetMapper(popMapper)
コード例 #8
0
ファイル: gauss.py プロジェクト: gnastacast/fruiting_bodies
def main():
    colors = vtk.vtkNamedColors()

    colors.SetColor("PopColor", [230, 230, 230, 255])

    # fileName = get_program_parameters()

    keys = ['NUMBER_POINTS', 'MONTHLY_PAYMENT', 'INTEREST_RATE', 'LOAN_AMOUNT', 'TIME_LATE']

    # Read in the data and make an unstructured data set.
    dataSet = make_dataset()

    # pts[:,0] = pts[:,0] ** 3
    # npData.SetPoints(npData.GetPoints())

    # # Construct the pipeline for the original population.
    # popSplatter = vtk.vtkGaussianSplatter()
    # popSplatter.SetInputData(dataSet)
    # popSplatter.SetSampleDimensions(100, 100, 100)
    # popSplatter.SetRadius(0.1)
    # popSplatter.ScalarWarpingOff()

    # popSurface = vtk.vtkContourFilter()
    # popSurface.SetInputConnection(popSplatter.GetOutputPort())
    # popSurface.SetValue(0, 0.01)

    # popMapper = vtk.vtkPolyDataMapper()
    # popMapper.SetInputConnection(popSurface.GetOutputPort())
    # popMapper.ScalarVisibilityOff()

    # popActor = vtk.vtkActor()
    # popActor.SetMapper(popMapper)
    # popActor.GetProperty().SetOpacity(0.3)
    # popActor.GetProperty().SetColor(colors.GetColor3d("PopColor"))

    # Construct the pipeline for the delinquent population.
    lateSplatter = vtk.vtkGaussianSplatter()
    lateSplatter.SetInputData(dataSet)
    lateSplatter.SetSampleDimensions(150, 150, 150)
    lateSplatter.SetRadius(0.1)
    lateSplatter.SetScaleFactor(.001)

    lateSurface = vtk.vtkContourFilter()
    lateSurface.SetInputConnection(lateSplatter.GetOutputPort())
    lateSurface.SetValue(0, 0.01)

    lateMapper = vtk.vtkPolyDataMapper()
    lateMapper.SetInputConnection(lateSurface.GetOutputPort())
    lateMapper.ScalarVisibilityOff()

    lateActor = vtk.vtkActor()
    lateActor.SetMapper(lateMapper)
    lateActor.GetProperty().SetColor(colors.GetColor3d("Red"))

    # Create axes.
    lateSplatter.Update()
    bounds = lateSplatter.GetOutput().GetBounds()

    axes = vtk.vtkAxes()
    axes.SetOrigin(bounds[0], bounds[2], bounds[4])
    axes.SetScaleFactor(lateSplatter.GetOutput().GetLength() / 5)

    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)

    # Visualize.
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderWindow)

    renderer.AddActor(axesActor)
    renderer.AddActor(lateActor)
    renderer.SetBackground(colors.GetColor3d("powder_blue"))

    # Enable user interface interactor
    renderWindow.Render()

    def update(self):
        pts = dataSet.GetPoints()
        pts.SetPoint(0, [0,0,np.sin(time.time())])
        pts.Modified()
        interactor.Render()

    # Sign up to receive TimerEvent
    cb = vtkTimerCallback()
    cb.update = update

    interactor.AddObserver('TimerEvent', cb.execute)
    timerId = interactor.CreateRepeatingTimer(10);

    interactor.Start()
コード例 #9
0
ファイル: financialField.py プロジェクト: marwan-abdellah/VTK
    def testFinancialField(self):

        size = 3187  #maximum number possible

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

        # extract data from field as a polydata (just points), then extract scalars
        fdr = vtk.vtkDataObjectReader()
        fdr.SetFileName(VTK_DATA_ROOT + "/Data/financial.vtk")
        do2ds = vtk.vtkDataObjectToDataSetFilter()
        do2ds.SetInputConnection(fdr.GetOutputPort())
        do2ds.SetDataSetTypeToPolyData()
        #format: component#, arrayname, arraycomp, minArrayId, maxArrayId, normalize
        do2ds.DefaultNormalizeOn()
        do2ds.SetPointComponent(0, xAxis, 0)
        do2ds.SetPointComponent(1, yAxis, 0, 0, size, 1)
        do2ds.SetPointComponent(2, zAxis, 0)
        do2ds.Update()
        if fdr.GetOutput().GetFieldData().GetAbstractArray(
                "Some Text").GetValue(0) != "Test me":
            raise RuntimeError, 'Could not properly read string array "Some Text"'
        fd2ad = vtk.vtkFieldDataToAttributeDataFilter()
        fd2ad.SetInputConnection(do2ds.GetOutputPort())
        fd2ad.SetInputFieldToDataObjectField()
        fd2ad.SetOutputAttributeDataToPointData()
        fd2ad.DefaultNormalizeOn()
        fd2ad.SetScalarComponent(0, scalar, 0)

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

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

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

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

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

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

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

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

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

        # render and interact with data

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

        img_file = "financialField.png"
        vtk.test.Testing.compareImage(
            iRen.GetRenderWindow(),
            vtk.test.Testing.getAbsImagePath(img_file),
            threshold=25)
        vtk.test.Testing.interact()
コード例 #10
0
ファイル: ASDVTKMomActors.py プロジェクト: tamlovincy/UppASD
    def Add_MomActors(self,ren,renWin,iren,ASDdata,window):
        """Main wrapper to add the needed actors for visualization of the moments.
        Class that contains the data structures for creation of the glyphs or the 
        visualization of the magnetic moments. It also has the capacity to create 
        tessellations for the visualization of volume vendering.

        Args:
            ren: current renderer.
            renWin: current rendering window.
            iren: current interactor for the renderer.
            ASDdata: class where the data read from the ASD simulations is stored.
            window: QMainWindow object where the visualization is performed.

        Author
        ----------
        Jonathan Chico
        """

        import vtk
        import numpy as np

        ASDMomActors.timer_count=0
        ASDMomActors.camera_pos=np.zeros(3,dtype=np.float32)
        ASDMomActors.camera_focal=np.zeros(3,dtype=np.float32)
        ASDMomActors.camera_yaw=0.0
        ASDMomActors.camera_roll=0.0
        ASDMomActors.camera_pitch=0.0
        ASDMomActors.camera_azimuth=0.0
        ASDMomActors.camera_elevation=0.0
        ASDMomActors.kmc_disp=ASDdata.kmc_flag
        ASDMomActors.cluster_disp=ASDdata.cluster_flag
        ASDMomActors.glob_color=ASDdata.colors
        #-----------------------------------------------------------------------
        # Look up tables for colors
        #-----------------------------------------------------------------------
        # This is a diverging RWB color mapping based on the work of Kenneth
        # Moreland and with the vtk examples provided by Andrew Maclean
        if ASDdata.flag2D:
            ASDMomActors.lut = vtk.vtkLookupTable()
            num_colors = 256
            ASDMomActors.lut.SetNumberOfTableValues(num_colors)
            ASDMomActors.transfer_func = vtk.vtkColorTransferFunction()
            ASDMomActors.transfer_func.SetColorSpaceToDiverging()
            ASDMomActors.transfer_func.AddRGBPoint(0, 0.230, 0.299, 0.754)
            ASDMomActors.transfer_func.AddRGBPoint(1, 0.706, 0.016, 0.150)
            for ii,ss in enumerate([float(xx)/float(num_colors) for xx in range(num_colors)]):
                cc = ASDMomActors.transfer_func.GetColor(ss)
                ASDMomActors.lut.SetTableValue(ii, cc[0], cc[1], cc[2], 1.0)
            ASDMomActors.lut.Build()
        else:
            ASDMomActors.lut = vtk.vtkLookupTable()
            num_colors = 256
            ASDMomActors.lut.SetNumberOfTableValues(num_colors)
            ASDMomActors.transfer_func = vtk.vtkColorTransferFunction()
            ASDMomActors.transfer_func.SetColorSpaceToDiverging()
            ASDMomActors.transfer_func.AddRGBPoint(-0, 0.230, 0.299, 0.754)
            ASDMomActors.transfer_func.AddRGBPoint( 1, 0.706, 0.016, 0.150)
            for ii,ss in enumerate([float(xx)/float(num_colors) for xx in range(num_colors)]):
                cc = ASDMomActors.transfer_func.GetColor(ss)
                ASDMomActors.lut.SetTableValue(ii, cc[0], cc[1], cc[2], 1.0)
            ASDMomActors.lut.Build()
        #-----------------------------------------------------------------------
        # Data structures for the generation of the smooth grid
        #-----------------------------------------------------------------------
        # Passing the data from the full system to the PolyData
        ASDMomActors.src=vtk.vtkPolyData()
        ASDMomActors.src.SetPoints(ASDdata.coord)
        ASDMomActors.src.GetPointData().SetScalars(ASDdata.colors[2])
        ASDMomActors.src.GetPointData().SetVectors(ASDdata.moments)
        scalar_range = ASDMomActors.src.GetScalarRange()
        #-----------------------------------------------------------------------
        # Finding useful geometrical information of the sample
        #-----------------------------------------------------------------------
        # Finding the middle of the sample
        # Also making sure that if the sample is 2D one has no problem with bounds
        # this is mostly useful if splatters are used
        (ASDMomActors.xmin,ASDMomActors.xmax,ASDMomActors.ymin,ASDMomActors.ymax,\
        ASDMomActors.zmin,ASDMomActors.zmax)= ASDMomActors.src.GetBounds()
        if ASDMomActors.xmin==ASDMomActors.xmax:
            ASDMomActors.xmin=0.0
            ASDMomActors.xmax=1.0
        if ASDMomActors.ymin==ASDMomActors.ymax:
            ASDMomActors.ymin=0.0
            ASDMomActors.ymax=1.0
        if ASDMomActors.zmin==ASDMomActors.zmax:
            ASDMomActors.zmin=0.0
            ASDMomActors.zmax=1.0
        ASDMomActors.xmid = (ASDMomActors.xmin+ASDMomActors.xmax)*0.5
        ASDMomActors.ymid = (ASDMomActors.ymin+ASDMomActors.ymax)*0.5
        ASDMomActors.zmid = (ASDMomActors.zmin+ASDMomActors.zmax)*0.5
        ASDMomActors.height=max(ASDMomActors.xmax,ASDMomActors.ymax,ASDMomActors.zmax)*1.75
        self.dist_x=np.absolute(ASDMomActors.xmax-ASDMomActors.xmin)
        self.dist_y=np.absolute(ASDMomActors.ymax-ASDMomActors.ymin)
        self.dist_z=np.absolute(ASDMomActors.zmax-ASDMomActors.zmin)
        ASDMomActors.camera_pos[0]=ASDMomActors.xmid
        ASDMomActors.camera_pos[1]=ASDMomActors.ymid
        ASDMomActors.camera_pos[2]=ASDMomActors.height
        ASDMomActors.camera_focal[0]=ASDMomActors.xmid
        ASDMomActors.camera_focal[1]=ASDMomActors.ymid
        ASDMomActors.camera_focal[2]=ASDMomActors.zmid
        # The delaunay tessellation seems to be the best way to transform the point cloud
        # to a surface for volume rendering, the problem is that it is too slow for large
        # data sets, meaning that the best option is first to prune out the data to ensure
        # that one has a manageable number of data points over which to do the construction
        # surface reconstruction and splatter techniques also can be used to generate something
        # akin to the kind of surfaces we want. The issue is that they transform the data to a
        # regular mesh by default. And thus it is a problem for most kind of systems
        if ASDdata.flag2D:
            # Passing the data to generate a triangulation of the data
            ASDMomActors.MagDensMethod = vtk.vtkDelaunay2D()
            ASDMomActors.MagDensMethod.SetInputData(ASDMomActors.src)
            ASDMomActors.MagDensMethod.BoundingTriangulationOff()
            ASDMomActors.MagDensMethod.SetTolerance(0.005)
            # Time the execution of the delaunay tessellation
            SM_timer = vtk.vtkExecutionTimer()
            SM_timer.SetFilter(ASDMomActors.MagDensMethod)
            ASDMomActors.MagDensMethod.Update()
            SM = SM_timer.GetElapsedWallClockTime()
            print ("2D Delaunay:", SM)
            # Creating the mapper for the smooth surfaces
            ASDMomActors.MagDensMap = vtk.vtkDataSetMapper()
            ASDMomActors.MagDensMap.SetScalarRange(scalar_range)
            ASDMomActors.MagDensMap.SetInputConnection(ASDMomActors.MagDensMethod.GetOutputPort())
            ASDMomActors.MagDensMap.SetLookupTable(ASDMomActors.lut)
            ASDMomActors.MagDensMap.SetColorModeToMapScalars()
            ASDMomActors.MagDensMap.Update()
            # Creating the actor for the smooth surfaces
            ASDMomActors.MagDensActor = vtk.vtkLODActor()
            ASDMomActors.MagDensActor.SetMapper(ASDMomActors.MagDensMap)
            ASDMomActors.MagDensActor.GetProperty().SetOpacity(0.75)
            ASDMomActors.MagDensActor.GetProperty().EdgeVisibilityOff()
            if window.DensBox.isChecked():
                ASDMomActors.MagDensActor.VisibilityOn()
            else:
                ASDMomActors.MagDensActor.VisibilityOff()
        else:
            #-------------------------------------------------------------------
            # Setting the parameters for the visualization of 3D structures with
            # splatters
            #-------------------------------------------------------------------
            ASDMomActors.MagDensMethod = vtk.vtkGaussianSplatter()
            ASDMomActors.MagDensMethod.SetInputData(ASDMomActors.src)
            #-------------------------------------------------------------------
            # Options for the Gaussian splatter. These determine the quality of the
            # rendering, increasing the radius smoothens out the volume but performance
            # decreases rapidly
            #-------------------------------------------------------------------
            dist=(np.asarray(ASDMomActors.src.GetPoint(0))-np.asarray(ASDMomActors.src.GetPoint(1)))
            norm=np.sqrt(dist.dot(dist))
            if norm<1:
                rad_fac=0.040
            else:
                rad_fac=0.40
            ASDMomActors.MagDensMethod.SetRadius(rad_fac)
            ASDMomActors.MagDensMethod.ScalarWarpingOn()
            #-------------------------------------------------------------------
            # The exponent factor determines how fast the gaussian splatter decay
            # they again can be used to improve quality at the sake of rendering time
            #-------------------------------------------------------------------
            ASDMomActors.MagDensMethod.SetExponentFactor(-10)
            ASDMomActors.MagDensMethod.NormalWarpingOn()
            ASDMomActors.MagDensMethod.SetEccentricity(10)
            #-------------------------------------------------------------------
            # The Null value can be used to try to eliminate contributions not belonging
            # to the actual sample
            #-------------------------------------------------------------------
            ASDMomActors.MagDensMethod.SetNullValue(-10)
            #-------------------------------------------------------------------
            # Set the actual size of the rendering model
            #-------------------------------------------------------------------
            ASDMomActors.MagDensMethod.SetModelBounds(ASDMomActors.xmin,ASDMomActors.xmax,\
            ASDMomActors.ymin,ASDMomActors.ymax,ASDMomActors.zmin,ASDMomActors.zmax)
            # This should get rid of the problems when trying to map very thin structures in 2D
            if self.dist_x==min(self.dist_x,self.dist_y,self.dist_z) and self.dist_x<3:
                ASDMomActors.MagDensMethod.SetSampleDimensions(3,int(ASDMomActors.ymax),int(ASDMomActors.zmax))
            elif self.dist_y==min(self.dist_x,self.dist_y,self.dist_z) and self.dist_y<3:
                ASDMomActors.MagDensMethod.SetSampleDimensions(int(ASDMomActors.xmax),3,int(ASDMomActors.zmax))
            elif self.dist_z==min(self.dist_x,self.dist_y,self.dist_z) and self.dist_z<3:
                ASDMomActors.MagDensMethod.SetSampleDimensions(int(ASDMomActors.xmax),int(ASDMomActors.ymax),3)
            # Timming for the execution of the volume creation
            SP_timer = vtk.vtkExecutionTimer()
            SP_timer.SetFilter(ASDMomActors.MagDensMethod)
            ASDMomActors.MagDensMethod.Update()
            SP = SP_timer.GetElapsedWallClockTime()
            print ("3D vtkGaussianSplatter Method:", SP)
            # Scalar opacities
            funcOpacityScalar = vtk.vtkPiecewiseFunction()
            funcOpacityScalar.AddPoint(-1.00,0.00)
            funcOpacityScalar.AddPoint( 0.00,0.05)
            funcOpacityScalar.AddPoint( 0.50,0.50)
            funcOpacityScalar.AddPoint( 0.75,1.00)
            # Gradient opacities
            volumeGradientOpacity = vtk.vtkPiecewiseFunction()
            volumeGradientOpacity.AddPoint(0.000,0.0)
            volumeGradientOpacity.AddPoint(0.001,1.0)
            volumeGradientOpacity.AddPoint(1.000,1.0)
            # Volume properties
            ASDMomActors.volumeProperty = vtk.vtkVolumeProperty()
            ASDMomActors.volumeProperty.SetColor(ASDMomActors.transfer_func)
            ASDMomActors.volumeProperty.SetInterpolationTypeToLinear()
            ASDMomActors.volumeProperty.SetAmbient(0.6)
            ASDMomActors.volumeProperty.SetDiffuse(0.6)
            ASDMomActors.volumeProperty.SetSpecular(0.1)
            ASDMomActors.volumeProperty.SetGradientOpacity(volumeGradientOpacity)
            ASDMomActors.volumeProperty.SetScalarOpacity(funcOpacityScalar)
            # Volume Mapper
            ASDMomActors.MagDensMap = vtk.vtkSmartVolumeMapper()
            ASDMomActors.MagDensMap.SetInputConnection(ASDMomActors.MagDensMethod.GetOutputPort())
            # Volume Actor
            ASDMomActors.MagDensActor = vtk.vtkVolume()
            ASDMomActors.MagDensActor.SetMapper(ASDMomActors.MagDensMap)
            ASDMomActors.MagDensActor.SetProperty(self.volumeProperty)
            if window.DensBox.isChecked():
                ASDMomActors.MagDensActor.VisibilityOn()
            else:
                ASDMomActors.MagDensActor.VisibilityOff()
        #-----------------------------------------------------------------------
        # Data structures for the spins
        #-----------------------------------------------------------------------
        # Passing the data from the full system to the PolyData
        ASDMomActors.src_spins=vtk.vtkPolyData()
        ASDMomActors.src_spins.SetPoints(ASDdata.coord)
        ASDMomActors.src_spins.GetPointData().SetScalars(ASDdata.colors[2])
        ASDMomActors.src_spins.GetPointData().SetVectors(ASDdata.moments)
        scalar_range_spins = ASDMomActors.src_spins.GetScalarRange()
        #-----------------------------------------------------------------------
        # Data structures for the contours
        #-----------------------------------------------------------------------
        # Define the contour filters
        contours = vtk.vtkContourFilter()
        contours.SetInputConnection(ASDMomActors.MagDensMethod.GetOutputPort())
        # This generates the contours, it will do 5 between the -1 and 0.5 range
        cont_num=5
        range_cont=(-1,0.5)
        contours.GenerateValues(cont_num,range_cont)
        # Map the contours to graphical primitives
        contMapper = vtk.vtkPolyDataMapper()
        contMapper.SetInputConnection(contours.GetOutputPort())
        contMapper.SetScalarVisibility(False) # colored contours
        contMapper.SetScalarRange(scalar_range)
        # Create an actor for the contours
        ASDMomActors.contActor = vtk.vtkLODActor()
        ASDMomActors.contActor.SetMapper(contMapper)
        ASDMomActors.contActor.GetProperty().SetColor(0, 0, 0)
        ASDMomActors.contActor.GetProperty().SetLineWidth(1.0)
        ASDMomActors.contActor.VisibilityOff()
        #-----------------------------------------------------------------------
        # Setting information of the directions
        #-----------------------------------------------------------------------
        # Create vectors
        arrow = vtk.vtkArrowSource()
        arrow.SetTipRadius(0.20)
        arrow.SetShaftRadius(0.10)
        arrow.SetTipResolution(20)
        arrow.SetShaftResolution(20)
        # Create the mapper for the spins
        arrowMapper = vtk.vtkGlyph3DMapper()
        arrowMapper.SetSourceConnection(arrow.GetOutputPort())
        arrowMapper.SetInputData(ASDMomActors.src)
        arrowMapper.SetScaleFactor(0.50)
        arrowMapper.SetScalarVisibility(False)
        arrowMapper.SetScaleModeToNoDataScaling()
        arrowMapper.Update()
        # Define the vector actor for the spins
        ASDMomActors.vector = vtk.vtkLODActor()
        ASDMomActors.vector.SetMapper(arrowMapper)
        ASDMomActors.vector.GetProperty().SetSpecular(0.3)
        ASDMomActors.vector.GetProperty().SetSpecularPower(60)
        ASDMomActors.vector.GetProperty().SetAmbient(0.2)
        ASDMomActors.vector.GetProperty().SetDiffuse(0.8)
        ASDMomActors.vector.GetProperty().SetColor(0, 0, 0)
        ASDMomActors.vector.VisibilityOff()
        #-----------------------------------------------------------------------
        # Setting information of the spins
        #-----------------------------------------------------------------------
        # Create vectors
        ASDMomActors.spinarrow = vtk.vtkArrowSource()
        ASDMomActors.spinarrow.SetTipRadius(0.20)
        ASDMomActors.spinarrow.SetShaftRadius(0.10)
        ASDMomActors.spinarrow.SetTipResolution(20)
        ASDMomActors.spinarrow.SetShaftResolution(20)
        # Create the mapper for the spins
        ASDMomActors.SpinMapper = vtk.vtkGlyph3DMapper()
        ASDMomActors.SpinMapper.SetSourceConnection(ASDMomActors.spinarrow.GetOutputPort())
        ASDMomActors.SpinMapper.SetInputData(ASDMomActors.src_spins)
        ASDMomActors.SpinMapper.SetScalarRange(scalar_range_spins)
        ASDMomActors.SpinMapper.SetScaleFactor(0.50)
        ASDMomActors.SpinMapper.SetScaleModeToNoDataScaling()
        ASDMomActors.SpinMapper.SetLookupTable(self.lut)
        ASDMomActors.SpinMapper.SetColorModeToMapScalars()
        ASDMomActors.SpinMapper.Update()
        # Define the vector actor for the spins
        ASDMomActors.Spins = vtk.vtkLODActor()
        ASDMomActors.Spins.SetMapper(ASDMomActors.SpinMapper)
        ASDMomActors.Spins.GetProperty().SetSpecular(0.3)
        ASDMomActors.Spins.GetProperty().SetSpecularPower(60)
        ASDMomActors.Spins.GetProperty().SetAmbient(0.2)
        ASDMomActors.Spins.GetProperty().SetDiffuse(0.8)
        if window.SpinsBox.isChecked():
            ASDMomActors.Spins.VisibilityOn()
        else:
            ASDMomActors.Spins.VisibilityOff()
        if (ASDdata.kmc_flag):
            #-------------------------------------------------------------------
            # Setting data structures for the KMC particle visualization
            #-------------------------------------------------------------------
            ASDMomActors.KMC_src=vtk.vtkPolyData()
            ASDMomActors.KMC_src.SetPoints(ASDdata.coord_KMC)
            # Atom sphere
            KMC_part = vtk.vtkSphereSource()
            KMC_part.SetRadius(1.75)
            KMC_part.SetThetaResolution(40)
            KMC_part.SetPhiResolution(40)
            # Atom glyph
            KMC_part_mapper = vtk.vtkGlyph3DMapper()
            KMC_part_mapper.SetInputData(ASDMomActors.KMC_src)
            KMC_part_mapper.SetSourceConnection(KMC_part.GetOutputPort())
            KMC_part_mapper.SetScaleFactor(0.5)
            KMC_part_mapper.ClampingOn()
            KMC_part_mapper.SetScaleModeToNoDataScaling()
            KMC_part_mapper.SetColorModeToMapScalars()
            KMC_part_mapper.Update()
            # Atoms actors
            ASDMomActors.KMC_part_actor = vtk.vtkLODActor()
            ASDMomActors.KMC_part_actor.SetMapper(KMC_part_mapper)
            ASDMomActors.KMC_part_actor.GetProperty().SetOpacity(0.9)
            ASDMomActors.KMC_part_actor.GetProperty().SetColor(0.0, 0.0, 1.0)
            ASDMomActors.KMC_part_actor.GetProperty().EdgeVisibilityOn()
            ASDMomActors.KMC_part_actor.GetProperty().SetEdgeColor(0,0,0)
        #-----------------------------------------------------------------------
        # Setting information of the renderer
        #-----------------------------------------------------------------------
        # Define the renderer
        # Add the actors to the scene
        if ASDdata.flag2D:
            ren.AddActor(ASDMomActors.MagDensActor)
        else:
            ren.AddViewProp(ASDMomActors.MagDensActor)
        ren.AddActor(ASDMomActors.Spins)
        ren.AddActor(ASDMomActors.vector)
        ren.AddActor(ASDMomActors.contActor)
        #If the KMC particles are present add them to the renderer
        if ASDdata.kmc_flag:
            ren.AddActor(ASDMomActors.KMC_part_actor)
        # Defining the camera directions
        ren.GetActiveCamera().Azimuth(ASDMomActors.camera_azimuth)
        ren.GetActiveCamera().Elevation(ASDMomActors.camera_elevation)
        ren.GetActiveCamera().Yaw(ASDMomActors.camera_yaw)
        ren.GetActiveCamera().Roll(ASDMomActors.camera_roll)
        ren.GetActiveCamera().Pitch(ASDMomActors.camera_pitch)
        ren.GetActiveCamera().SetFocalPoint(ASDMomActors.camera_focal)
        ren.GetActiveCamera().SetPosition(ASDMomActors.camera_pos)
        ren.GetActiveCamera().SetViewUp(0,1,0)
        #-----------------------------------------------------------------------
        # Start the renderer
        #-----------------------------------------------------------------------
        iren.Start()
        renWin.Render()
        return;
コード例 #11
0
# represent the array scalar (TIME_LATE)
calc.AddScalarVariable("s", scalar, 0)
# Divide scalar by max (applies division to all components of the array)
calc.SetFunction("s / %f"%max)
# The output array will be called resArray
calc.SetResultArrayName("resArray")

# Use AssignAttribute to make resArray the active scalar field
aa = vtk.vtkAssignAttribute()
aa.SetInputConnection(calc.GetOutputPort())
aa.Assign("resArray", "SCALARS", "POINT_DATA")
aa.Update()

# construct pipeline for original population
# GaussianSplatter -> Contour -> Mapper -> Actor
popSplatter = vtk.vtkGaussianSplatter()
popSplatter.SetInputConnection(aa.GetOutputPort())
popSplatter.SetSampleDimensions(50, 50, 50)
popSplatter.SetRadius(0.05)
popSplatter.ScalarWarpingOff()

popSurface = vtk.vtkContourFilter()
popSurface.SetInputConnection(popSplatter.GetOutputPort())
popSurface.SetValue(0, 0.01)

popMapper = vtk.vtkPolyDataMapper()
popMapper.SetInputConnection(popSurface.GetOutputPort())
popMapper.ScalarVisibilityOff()

popActor = vtk.vtkActor()
popActor.SetMapper(popMapper)
コード例 #12
0
ファイル: financialField3.py プロジェクト: DeepDriving/VTK-1
    def testFinancialField(self):
        """
            Demonstrate the use and manipulation of fields and use of
            vtkProgrammableDataObjectSource. This creates fields the hard way
            (as compared to reading a vtk field file), but shows you how to
            interface to your own raw data.

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

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

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

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

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

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

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

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

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

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

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

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

            dos.GetOutput().SetFieldData(field)

        dos.SetExecuteMethod(parseFile)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        # render and interact with data

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

        img_file = "financialField3.png"
        vtk.test.Testing.compareImage(
            iRen.GetRenderWindow(),
            vtk.test.Testing.getAbsImagePath(img_file),
            threshold=25)
        vtk.test.Testing.interact()
コード例 #13
0
def main():
    colors = vtk.vtkNamedColors()

    colors.SetColor("PopColor", [230, 230, 230, 255])

    fileName = get_program_parameters()

    keys = [
        'NUMBER_POINTS', 'MONTHLY_PAYMENT', 'INTEREST_RATE', 'LOAN_AMOUNT',
        'TIME_LATE'
    ]

    # Read in the data and make an unstructured data set.
    dataSet = make_dataset(fileName, keys)

    # Construct the pipeline for the original population.
    popSplatter = vtk.vtkGaussianSplatter()
    popSplatter.SetInputData(dataSet)
    popSplatter.SetSampleDimensions(100, 100, 100)
    popSplatter.SetRadius(0.05)
    popSplatter.ScalarWarpingOff()

    popSurface = vtk.vtkContourFilter()
    popSurface.SetInputConnection(popSplatter.GetOutputPort())
    popSurface.SetValue(0, 0.01)

    popMapper = vtk.vtkPolyDataMapper()
    popMapper.SetInputConnection(popSurface.GetOutputPort())
    popMapper.ScalarVisibilityOff()

    popActor = vtk.vtkActor()
    popActor.SetMapper(popMapper)
    popActor.GetProperty().SetOpacity(0.3)
    popActor.GetProperty().SetColor(colors.GetColor3d("PopColor"))

    # Construct the pipeline for the delinquent population.
    lateSplatter = vtk.vtkGaussianSplatter()
    lateSplatter.SetInputData(dataSet)
    lateSplatter.SetSampleDimensions(50, 50, 50)
    lateSplatter.SetRadius(0.05)
    lateSplatter.SetScaleFactor(0.005)

    lateSurface = vtk.vtkContourFilter()
    lateSurface.SetInputConnection(lateSplatter.GetOutputPort())
    lateSurface.SetValue(0, 0.01)

    lateMapper = vtk.vtkPolyDataMapper()
    lateMapper.SetInputConnection(lateSurface.GetOutputPort())
    lateMapper.ScalarVisibilityOff()

    lateActor = vtk.vtkActor()
    lateActor.SetMapper(lateMapper)
    lateActor.GetProperty().SetColor(colors.GetColor3d("Red"))

    # 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)

    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)

    # Graphics stuff.
    renderer = vtk.vtkRenderer()

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

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

    # Set up the renderer.
    renderer.AddActor(lateActor)
    renderer.AddActor(axesActor)
    renderer.AddActor(popActor)
    renderer.SetBackground(colors.GetColor3d("Wheat"))
    renWin.SetSize(640, 480)

    renderer.ResetCamera()
    renderer.GetActiveCamera().Dolly(1.3)
    renderer.ResetCameraClippingRange()

    # Interact with the data.
    renWin.Render()
    interactor.Start()
コード例 #14
0
    def _render_blurry_particles(self, particles_dataset):
        particles_per_species = dict((k, vtk.vtkPoints()) for k in self._species_idmap.iterkeys())

        scaling = self.settings.scaling

        position_idx = particles_dataset.dtype.names.index('position')
        species_id_idx = particles_dataset.dtype.names.index('species_id')
        for p in particles_dataset:
            pos = p[position_idx]
            display_species_id = self._species_idmap.get(p[species_id_idx])
            if display_species_id is None:
                continue
            particles_per_species[display_species_id].InsertNextPoint(
                pos * scaling / self._world_size)

        nx = ny = nz = self.settings.fluorimetry_axial_voxel_number

        for display_species_id, points in particles_per_species.iteritems():
            poly_data = vtk.vtkPolyData()
            poly_data.SetPoints(points)
            poly_data.ComputeBounds()

            pattr = self._pattrs[display_species_id]
            # Calc standard deviation of gauss distribution function
            wave_length = pattr['fluorimetry_wave_length']
            sigma = scaling * 0.5 * wave_length / self._world_size

            # Create guassian splatter
            gs = vtk.vtkGaussianSplatter()
            gs.SetInput(poly_data)
            gs.SetSampleDimensions(nx, ny, nz)
            gs.SetRadius(sigma)
            gs.SetExponentFactor(-.5)
            gs.ScalarWarpingOff()
            gs.SetModelBounds([-sigma, scaling + sigma] * 3)
            gs.SetAccumulationModeToMax()

            # Create filter for volume rendering
            filter = vtk.vtkImageShiftScale()
            # Scales to unsigned char
            filter.SetScale(255. * pattr['fluorimetry_brightness'])
            filter.ClampOverflowOn()
            filter.SetOutputScalarTypeToUnsignedChar()
            filter.SetInputConnection(gs.GetOutputPort())

            mapper = vtk.vtkFixedPointVolumeRayCastMapper()
            mapper.SetInputConnection(filter.GetOutputPort())

            volume = vtk.vtkVolume()
            property = volume.GetProperty() # vtk.vtkVolumeProperty()
            color = pattr['fluorimetry_luminescence_color']
            color_tfunc = vtk.vtkColorTransferFunction()
            color_tfunc.AddRGBPoint(0, color[0], color[1], color[2])
            property.SetColor(color_tfunc)
            opacity_tfunc = vtk.vtkPiecewiseFunction()
            opacity_tfunc.AddPoint(0, 0.0)
            opacity_tfunc.AddPoint(255., 1.0)
            property.SetScalarOpacity(opacity_tfunc)
            property.SetInterpolationTypeToLinear()

            if self.settings.fluorimetry_shadow_display:
                property.ShadeOn()
            else:
                property.ShadeOff()

            volume.SetMapper(mapper)

            self.renderer.AddVolume(volume)
コード例 #15
0
def main():
    ifn = get_program_parameters()

    colors = vtk.vtkNamedColors()

    reader = vtk.vtkDataObjectReader()
    reader.SetFileName(ifn)

    size = 3187  # maximum number possible

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

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

    # Construct the pipeline for the original population.
    popSplatter = vtk.vtkGaussianSplatter()
    popSplatter.SetInputConnection(fd2ad.GetOutputPort())
    popSplatter.SetSampleDimensions(150, 150, 150)
    popSplatter.SetRadius(0.05)
    popSplatter.ScalarWarpingOff()

    popSurface = vtk.vtkMarchingContourFilter()
    popSurface.SetInputConnection(popSplatter.GetOutputPort())
    popSurface.SetValue(0, 0.01)
    popMapper = vtk.vtkPolyDataMapper()
    popMapper.SetInputConnection(popSurface.GetOutputPort())
    popMapper.ScalarVisibilityOff()
    popActor = vtk.vtkActor()
    popActor.SetMapper(popMapper)
    popActor.GetProperty().SetOpacity(0.3)
    popActor.GetProperty().SetColor(colors.GetColor3d("Gold"))

    # Construct the pipeline for the delinquent population.
    lateSplatter = vtk.vtkGaussianSplatter()
    lateSplatter.SetInputConnection(fd2ad.GetOutputPort())
    lateSplatter.SetSampleDimensions(150, 150, 150)
    lateSplatter.SetRadius(0.05)
    lateSplatter.SetScaleFactor(0.05)

    lateSurface = vtk.vtkMarchingContourFilter()
    lateSurface.SetInputConnection(lateSplatter.GetOutputPort())
    lateSurface.SetValue(0, 0.01)
    lateMapper = vtk.vtkPolyDataMapper()
    lateMapper.SetInputConnection(lateSurface.GetOutputPort())
    lateMapper.ScalarVisibilityOff()
    lateActor = vtk.vtkActor()
    lateActor.SetMapper(lateMapper)
    lateActor.GetProperty().SetColor(colors.GetColor3d("Tomato"))

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

    # Label the axes.
    XText = vtk.vtkVectorText()
    XText.SetText(xAxis)
    XTextMapper = vtk.vtkPolyDataMapper()
    XTextMapper.SetInputConnection(XText.GetOutputPort())

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

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

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

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

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

    # Add the actors to the renderer, set the background and size.
    renderer.AddActor(axesActor)
    renderer.AddActor(lateActor)
    renderer.AddActor(XActor)
    renderer.AddActor(YActor)
    renderer.AddActor(ZActor)
    renderer.AddActor(popActor)
    renderer.SetBackground(colors.GetColor3d("SlateGray"))
    renderWindow.SetSize(650, 480)

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

    # Render and interact with the data.

    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderWindow)
    renderWindow.Render()
    interactor.Start()
コード例 #16
0
def dualSurfaceRendering(image1, image2):

    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    renWin.PolygonSmoothingOn()
    renWin.SetSize(400, 400)

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

    # skinMesh = createMesh(image1,(int)(image1.GetScalarRange()[0]),(int)(image1.GetScalarRange()[1]-1))
    skinMesh = createMesh(image1, 0, 255)
    boneMesh = createThresholdMesh(image2, 0, 255)
    ##########################################################
    # polydata=vtk.vtkPolyData()
    # polydata.SetPoints(boneMesh.GetPoints())
    splatter = vtk.vtkGaussianSplatter()
    splatter.SetInputData(boneMesh)
    splatter.SetRadius(0.02)
    surface = vtk.vtkContourFilter()
    surface.SetInputConnection(splatter.GetOutputPort())
    surface.SetValue(0, 0.01)
    # # Convert the image to a polydata
    # imageDataGeometryFilter = vtk.vtkImageDataGeometryFilter()
    # imageDataGeometryFilter.SetInputData(image2)
    # imageDataGeometryFilter.Update()
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(surface.GetOutputPort())
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    # actor.GetProperty().SetPointSize(0.01)
    #############################################################
    # sigmoidMesh = createThresholdMesh(sigmoid_image,0,1)
    # boneMesh = createThresholdMesh(image1,(int)(image1.GetScalarRange()[1]-1), (int)(image1.GetScalarRange()[1]))
    skinMapper = vtk.vtkPolyDataMapper()
    skinMapper.SetInputData(skinMesh)
    skinMapper.ScalarVisibilityOff()

    skinActor = vtk.vtkActor()
    skinActor.SetMapper(skinMapper)
    skinActor.GetProperty().SetColor(1.0, 1.0, 1.0)
    skinActor.GetProperty().SetOpacity(1.0)
    skinActor.GetProperty().SetAmbient(0.1)
    skinActor.GetProperty().SetDiffuse(0.7)
    skinActor.GetProperty().SetSpecular(0.1)

    boneMapper = vtk.vtkPolyDataMapper()
    boneMapper.SetInputData(boneMesh)
    boneMapper.ScalarVisibilityOff()

    boneActor = vtk.vtkActor()
    boneActor.SetMapper(boneMapper)
    boneActor.GetProperty().SetColor(1.0, 0.0, 0.0)
    boneActor.GetProperty().SetAmbient(0.2)
    boneActor.GetProperty().SetDiffuse(0.7)
    boneActor.GetProperty().SetSpecular(0.2)
    boneActor.GetProperty().SetOpacity(1.0)
    # boneActor.GetProperty().SetPointSize(100)

    # sigmoidMapper = vtk.vtkPolyDataMapper()
    # sigmoidMapper.SetInputData(sigmoidMesh)
    # sigmoidMapper.ScalarVisibilityOff()
    #
    # sigmoidActor = vtk.vtkActor()
    # sigmoidActor.SetMapper(sigmoidMapper)
    # sigmoidActor.GetProperty().SetColor(0.0,1.0,0.0)
    # sigmoidActor.GetProperty().SetAmbient(0.2)
    # sigmoidActor.GetProperty().SetDiffuse(0.7)
    # sigmoidActor.GetProperty().SetSpecular(0.2)
    # sigmoidActor.GetProperty().SetOpacity(1.0)

    sphere_view = vtk.vtkSphereSource()
    # sphere_view.SetOrigin([-48.96,-48.96,-48.42])
    # sphere_view.SetSpacing(0.18,0.18,0.18)
    # 210.0, 271.5, 314.5
    sphere_view.SetCenter(int(814 * 0.12), int(271 * 0.12), int(710 * 0.12))
    # sphere_view.SetCenter(int(250*0.18),int(150*0.18),int(600*0.18))
    sphere_view.SetRadius(1.0)
    # sphere_view.SetColor(0.0,1.0,1.0)
    # mapper
    mapper = vtk.vtkPolyDataMapper()
    if vtk.VTK_MAJOR_VERSION <= 5:
        mapper.SetInput(sphere_view.GetOutput())
    else:
        mapper.SetInputConnection(sphere_view.GetOutputPort())

    # actor
    sphere_actor = vtk.vtkActor()
    sphere_actor.SetMapper(mapper)
    sphere_actor.GetProperty().SetColor(1.0, 0.0, 1.0)

    ren.AddActor(boneActor)
    ren.AddActor(skinActor)
    ren.AddActor(sphere_actor)
    # ren.AddActor(sigmoidActor)
    ren.AddActor(actor)

    iren.Initialize()
    renWin.Render()
    iren.Start()
コード例 #17
0
    def _render_blurry_particles(self, particles_dataset):
        particles_per_species = dict((k, vtk.vtkPoints()) for k in self._species_idmap.iterkeys())

        scaling = self.settings.scaling

        position_idx = particles_dataset.dtype.names.index('position')
        species_id_idx = particles_dataset.dtype.names.index('species_id')
        for p in particles_dataset:
            pos = p[position_idx]
            display_species_id = self._species_idmap.get(p[species_id_idx])
            if display_species_id is None:
                continue
            particles_per_species[display_species_id].InsertNextPoint(
                pos * scaling / self._world_size)

        nx = ny = nz = self.settings.fluorimetry_axial_voxel_number

        for display_species_id, points in particles_per_species.iteritems():
            poly_data = vtk.vtkPolyData()
            poly_data.SetPoints(points)
            poly_data.ComputeBounds()

            pattr = self._pattrs[display_species_id]
            # Calc standard deviation of gauss distribution function
            wave_length = pattr['fluorimetry_wave_length']
            sigma = scaling * 0.5 * wave_length / self._world_size

            # Create guassian splatter
            gs = vtk.vtkGaussianSplatter()
            gs.SetInput(poly_data)
            gs.SetSampleDimensions(nx, ny, nz)
            gs.SetRadius(sigma)
            gs.SetExponentFactor(-.5)
            gs.ScalarWarpingOff()
            gs.SetModelBounds([-sigma, scaling + sigma] * 3)
            gs.SetAccumulationModeToMax()

            # Create filter for volume rendering
            filter = vtk.vtkImageShiftScale()
            # Scales to unsigned char
            filter.SetScale(255. * pattr['fluorimetry_brightness'])
            filter.ClampOverflowOn()
            filter.SetOutputScalarTypeToUnsignedChar()
            filter.SetInputConnection(gs.GetOutputPort())

            mapper = vtk.vtkFixedPointVolumeRayCastMapper()
            mapper.SetInputConnection(filter.GetOutputPort())

            volume = vtk.vtkVolume()
            property = volume.GetProperty() # vtk.vtkVolumeProperty()
            color = pattr['fluorimetry_luminescence_color']
            color_tfunc = vtk.vtkColorTransferFunction()
            color_tfunc.AddRGBPoint(0, color[0], color[1], color[2])
            property.SetColor(color_tfunc)
            opacity_tfunc = vtk.vtkPiecewiseFunction()
            opacity_tfunc.AddPoint(0, 0.0)
            opacity_tfunc.AddPoint(255., 1.0)
            property.SetScalarOpacity(opacity_tfunc)
            property.SetInterpolationTypeToLinear()

            if self.settings.fluorimetry_shadow_display:
                property.ShadeOn()
            else:
                property.ShadeOff()

            volume.SetMapper(mapper)

            self.renderer.AddVolume(volume)
コード例 #18
0
ファイル: SplatFace.py プロジェクト: zwlshine/VTKExamples
def main():
    colors = vtk.vtkNamedColors()

    fileName = get_program_parameters()

    # Create the RenderWindow, Renderer and Interactor.
    #
    ren1 = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren1)

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

    # Read cyberware file.
    #
    cyber = vtk.vtkPolyDataReader()
    cyber.SetFileName(fileName)

    normals = vtk.vtkPolyDataNormals()
    normals.SetInputConnection(cyber.GetOutputPort())

    mask = vtk.vtkMaskPoints()
    mask.SetInputConnection(normals.GetOutputPort())
    mask.SetOnRatio(8)
    # mask.RandomModeOn()

    splatter = vtk.vtkGaussianSplatter()
    splatter.SetInputConnection(mask.GetOutputPort())
    splatter.SetSampleDimensions(100, 100, 100)
    splatter.SetEccentricity(2.5)
    splatter.NormalWarpingOn()
    splatter.SetScaleFactor(1.0)
    splatter.SetRadius(0.025)

    contour = vtk.vtkContourFilter()
    contour.SetInputConnection(splatter.GetOutputPort())
    contour.SetValue(0, 0.25)

    splatMapper = vtk.vtkPolyDataMapper()
    splatMapper.SetInputConnection(contour.GetOutputPort())
    splatMapper.ScalarVisibilityOff()

    splatActor = vtk.vtkActor()
    splatActor.SetMapper(splatMapper)
    splatActor.GetProperty().SetColor(colors.GetColor3d("Flesh"))

    cyberMapper = vtk.vtkPolyDataMapper()
    cyberMapper.SetInputConnection(cyber.GetOutputPort())
    cyberMapper.ScalarVisibilityOff()

    cyberActor = vtk.vtkActor()
    cyberActor.SetMapper(cyberMapper)
    cyberActor.GetProperty().SetRepresentationToWireframe()
    cyberActor.GetProperty().SetColor(colors.GetColor3d("Turquoise"))

    # Add the actors to the renderer, set the background and size.
    #
    ren1.AddActor(cyberActor)
    ren1.AddActor(splatActor)
    ren1.SetBackground(colors.GetColor3d("Wheat"))
    renWin.SetSize(640, 480)

    camera = vtk.vtkCamera()
    camera.SetClippingRange(0.0332682, 1.66341)
    camera.SetFocalPoint(0.0511519, -0.127555, -0.0554379)
    camera.SetPosition(0.516567, -0.124763, -0.349538)
    camera.SetViewAngle(18.1279)
    camera.SetViewUp(-0.013125, 0.99985, -0.0112779)
    ren1.SetActiveCamera(camera)

    # Render the image.
    #
    renWin.Render()
    iren.Start()
コード例 #19
0
ファイル: SingleSplat.py プロジェクト: zwlshine/VTKExamples
def main():
    colors = vtk.vtkNamedColors()

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

    # Create single splat point
    pts = vtk.vtkPoints()
    verts = vtk.vtkCellArray()
    norms = vtk.vtkDoubleArray()
    scalars = vtk.vtkDoubleArray()

    x = [0.0] * 3
    pts.InsertNextPoint(x)
    norms.SetNumberOfTuples(1)
    norms.SetNumberOfComponents(3)
    n = [0] * 3
    n[0] = 0.707
    n[1] = 0.707
    n[2] = 0.0
    norms.InsertTuple(0, n)
    scalars.SetNumberOfTuples(1)
    scalars.SetNumberOfComponents(1)
    scalars.InsertTuple1(0, 1.0)

    verts.InsertNextCell(1)
    verts.InsertCellPoint(0)

    pData = vtk.vtkPolyData()
    pData.SetPoints(pts)
    pData.SetVerts(verts)
    pData.GetPointData().SetNormals(norms)
    pData.GetPointData().SetScalars(scalars)

    # Splat point and generate isosurface.
    splat = vtk.vtkGaussianSplatter()
    splat.SetInputData(pData)
    splat.SetModelBounds(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0)
    splat.SetSampleDimensions(75, 75, 75)
    splat.SetRadius(0.5)
    splat.SetEccentricity(5.0)
    splat.SetExponentFactor(-3.25)
    contour = vtk.vtkContourFilter()
    contour.SetInputConnection(splat.GetOutputPort())
    contour.SetValue(0, 0.9)
    splatMapper = vtk.vtkPolyDataMapper()
    splatMapper.SetInputConnection(contour.GetOutputPort())
    splatActor = vtk.vtkActor()
    splatActor.SetMapper(splatMapper)

    # Create outline.
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(splat.GetOutputPort())
    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInputConnection(outline.GetOutputPort())
    outlineActor = vtk.vtkActor()
    outlineActor.SetMapper(outlineMapper)
    outlineActor.GetProperty().SetColor(colors.GetColor3d("Brown"))

    # Create cone to indicate direction.
    cone = vtk.vtkConeSource()
    cone.SetResolution(24)
    coneMapper = vtk.vtkPolyDataMapper()
    coneMapper.SetInputConnection(cone.GetOutputPort())
    coneActor = vtk.vtkActor()
    coneActor.SetMapper(coneMapper)
    coneActor.SetScale(0.75, 0.75, 0.75)
    coneActor.RotateZ(45.0)
    coneActor.AddPosition(0.50, 0.50, 0.0)
    coneActor.GetProperty().SetColor(colors.GetColor3d("DeepPink"))
    #
    # Rendering stuff.
    #
    aren.SetBackground(colors.GetColor3d("Beige"))
    aren.AddActor(splatActor)
    aren.AddActor(outlineActor)
    aren.AddActor(coneActor)

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

    # Interact with the data.
    iren.Start()
コード例 #20
0
ファイル: financialField.py プロジェクト: kalmchocobo/VTK
    def testFinancialField(self):

        size = 3187 #maximum number possible

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


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

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

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

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

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

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

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

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

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

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


        # render and interact with data

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

        img_file = "financialField.png"
        vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)
        vtk.test.Testing.interact()
コード例 #21
0
    def testFinancialField(self):

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

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

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

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

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

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

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

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

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

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

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

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

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

            dos.GetOutput().SetFieldData(field)

        dos.SetExecuteMethod(parseFile)


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

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


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

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

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

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

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

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

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

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

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

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

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

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

        # render and interact with data

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

        img_file = "financialField3.png"
        vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)
        vtk.test.Testing.interact()
コード例 #22
0
ファイル: ASDVTKGenActors.py プロジェクト: tamlovincy/UppASD
 def Add_ClusterActors(self,ASDdata,iren,renWin,ren):
     import vtk
     ########################################################################
     # Data structures for the impurity cluster
     ########################################################################
     # Passing the data from the cluster to the PolyData
     src_clus=vtk.vtkPolyData()
     src_clus.SetPoints(ASDdata.coord_c)
     src_clus.GetPointData().SetScalars(ASDdata.colors_clus)
     # Passing the data from the selected impurities
     src_imp=vtk.vtkPolyData()
     src_imp.SetPoints(ASDdata.points_clus_imp)
     src_imp.GetPointData().SetScalars(ASDdata.colors_imp)
     src_imp.Modified()
     # Setting up the gaussian splatter for the clusters
     atomSource = vtk.vtkGaussianSplatter()
     atomSource.SetInputData(src_clus)
     atomSource.SetRadius(0.100)
     atomSource.ScalarWarpingOff()
     atomSource.SetExponentFactor(-20)
     atomSource.Update()
     bound=atomSource.GetModelBounds()
     atomSource.SetModelBounds(bound[0],bound[1],bound[2],bound[3],bound[4]*0.25,bound[5]*0.25)
     atomSource.Update()
     # Setting up a contour filter
     atomSurface = vtk.vtkContourFilter()
     atomSurface.SetInputConnection(atomSource.GetOutputPort())
     atomSurface.SetValue(0, 0.01)
     # Setting up the mapper
     atomMapper = vtk.vtkPolyDataMapper()
     atomMapper.SetInputConnection(atomSurface.GetOutputPort())
     atomMapper.ScalarVisibilityOff()
     # Creating the actor for the smooth surfaces
     ASDGenActors.atom = vtk.vtkActor()
     ASDGenActors.atom.SetMapper(atomMapper)
     ASDGenActors.atom.GetProperty().SetColor(0.0,0.0,0.0)
     ASDGenActors.atom.GetProperty().EdgeVisibilityOff()
     ASDGenActors.atom.GetProperty().SetSpecularPower(30)
     ASDGenActors.atom.GetProperty().SetAmbient(0.2)
     ASDGenActors.atom.GetProperty().SetDiffuse(0.8)
     ASDGenActors.atom.GetProperty().SetOpacity(0.25)
     # Set up imp sources
     atomSource_imp = vtk.vtkSphereSource()
     atomSource_imp.SetRadius(2.5)
     atomSource_imp.SetThetaResolution(20)
     atomSource_imp.SetPhiResolution(20)
     # Mapping the spheres to the actual points on the selected impurities
     atomMapper_imp = vtk.vtkGlyph3DMapper()
     atomMapper_imp.SetInputData(src_imp)
     atomMapper_imp.SetSourceConnection(atomSource_imp.GetOutputPort())
     atomMapper_imp.SetScaleFactor(0.2)
     atomMapper_imp.SetScaleModeToNoDataScaling()
     atomMapper_imp.Update()
     # Creating the selected impurity actors
     ASDGenActors.atom_imp = vtk.vtkLODActor()
     ASDGenActors.atom_imp.SetMapper(atomMapper_imp)
     ASDGenActors.atom_imp.GetProperty().SetSpecular(0.3)
     ASDGenActors.atom_imp.GetProperty().SetSpecularPower(30)
     ASDGenActors.atom_imp.GetProperty().SetAmbient(0.2)
     ASDGenActors.atom_imp.GetProperty().SetDiffuse(0.8)
     # If there is information about the cluster add the needed actors
     ren.AddActor(ASDGenActors.atom)
     ren.AddActor(ASDGenActors.atom_imp)
     ########################################################################
     # Start the renderer
     ########################################################################
     iren.Start()
     renWin.Render()
     return