Example #1
0
sCutterActor = vtk.vtkActor()
sCutterActor.SetMapper(sCutterMapper)
sCutterActor.GetProperty().SetColor(1, 1, 1)

# Outline
sOutline = vtk.vtkOutlineFilter()
sOutline.SetInputConnection(sample.GetOutputPort())

sOutlineMapper = vtk.vtkPolyDataMapper()
sOutlineMapper.SetInputConnection(sOutline.GetOutputPort())

sOutlineActor = vtk.vtkActor()
sOutlineActor.SetMapper(sOutlineMapper)

# Time the execution of the usual cutter
cutter_timer = vtk.vtkExecutionTimer()
cutter_timer.SetFilter(cutter)
cutter.Update()
CT = cutter_timer.GetElapsedWallClockTime()
print("vtkCutter:", CT)

# Time the execution of the usual cutter
cutter_timer.SetFilter(pcut)
pcut.Update()
CT = cutter_timer.GetElapsedWallClockTime()
print("vtkPlaneCutter:", CT)

# Time the execution of the filter w/o sphere tree
cutter_timer.SetFilter(scut)
scut.Update()
SC = cutter_timer.GetElapsedWallClockTime()
profile.GetPointData().SetScalars(scalars)

# Interpolate the points across the volume.
#
dim = 501
dim = 51

shepard1 = vtk.vtkShepardMethod()
shepard1.SetInputData(profile)
shepard1.SetModelBounds(-2,2, -2,2, -1,1)
shepard1.SetSampleDimensions(dim,dim,dim)
shepard1.SetNullValue(0)
shepard1.SetMaximumDistance(1)
shepard1.SetPowerParameter(1)

timer = vtk.vtkExecutionTimer()
timer.SetFilter(shepard1)
shepard1.Update()
wallClock = timer.GetElapsedWallClockTime()
print ("Shephard (P=1):", wallClock)

mapper1 = vtk.vtkDataSetMapper()
mapper1.SetInputConnection(shepard1.GetOutputPort())
mapper1.SetScalarRange(0,40)

block1 = vtk.vtkActor()
block1.SetMapper(mapper1)

shepard2 = vtk.vtkShepardMethod()
shepard2.SetInputData(profile)
shepard2.SetModelBounds(-2,2, -2,2, -1,1)
Example #3
0
profile.GetPointData().SetScalars(scalars)

# Interpolate the points across the volume.
#
dim = 501
dim = 51

shepard1 = vtk.vtkShepardMethod()
shepard1.SetInputData(profile)
shepard1.SetModelBounds(-2, 2, -2, 2, -1, 1)
shepard1.SetSampleDimensions(dim, dim, dim)
shepard1.SetNullValue(0)
shepard1.SetMaximumDistance(1)
shepard1.SetPowerParameter(1)

timer = vtk.vtkExecutionTimer()
timer.SetFilter(shepard1)
shepard1.Update()
wallClock = timer.GetElapsedWallClockTime()
print("Shephard (P=1):", wallClock)

mapper1 = vtk.vtkDataSetMapper()
mapper1.SetInputConnection(shepard1.GetOutputPort())
mapper1.SetScalarRange(0, 40)

block1 = vtk.vtkActor()
block1.SetMapper(mapper1)

shepard2 = vtk.vtkShepardMethod()
shepard2.SetInputData(profile)
shepard2.SetModelBounds(-2, 2, -2, 2, -1, 1)
snCutterActor = vtk.vtkActor()
snCutterActor.SetMapper(snCutterMapper)
snCutterActor.GetProperty().SetColor(1,1,1)

outlineT = vtk.vtkOutlineFilter()
outlineT.SetInputData(input)

outlineMapperT = vtk.vtkPolyDataMapper()
outlineMapperT.SetInputConnection(outlineT.GetOutputPort())

outlineActorT = vtk.vtkActor()
outlineActorT.SetMapper(outlineMapperT)

# Time the execution of the filter w/out scalar tree
cutter_timer = vtk.vtkExecutionTimer()
cutter_timer.SetFilter(cutter)
cutter.Update()
CT = cutter_timer.GetElapsedWallClockTime()
print ("vtkCutter:", CT)

# Time the execution of the filter w/ sphere tree
sCutter_timer = vtk.vtkExecutionTimer()
sCutter_timer.SetFilter(sCutter)
sCutter.Update()
ST = sCutter_timer.GetElapsedWallClockTime()
print ("Build sphere tree + execute once:", ST)

sCutter_timer = vtk.vtkExecutionTimer()
sCutter_timer.SetFilter(sCutter)
plane.Modified()
Example #5
0
contourActorT = vtk.vtkActor()
contourActorT.SetMapper(contourMapperT)
contourActorT.GetProperty().SetColor(1, 1, 1)

outlineT = vtk.vtkOutlineFilter()
outlineT.SetInputData(input)

outlineMapperT = vtk.vtkPolyDataMapper()
outlineMapperT.SetInputConnection(outlineT.GetOutputPort())

outlineActorT = vtk.vtkActor()
outlineActorT.SetMapper(outlineMapperT)

# Time the execution of the filter w/out scalar tree
CG_timer = vtk.vtkExecutionTimer()
CG_timer.SetFilter(cf)
cf.UseScalarTreeOff()
cf.Update()
CG = CG_timer.GetElapsedWallClockTime()
print("Contour Grid (no Scalar Tree):", CG)

# Time the execution of the filter w/ simple scalar tree
CG_timer0 = vtk.vtkExecutionTimer()
CG_timer0.SetFilter(cf)
cf.UseScalarTreeOn()
cf.SetScalarTree(sTree)
cf.Update()
CG0 = CG_timer0.GetElapsedWallClockTime()
print("Contour Grid (build & execute Simple Scalar Tree):", CG0)
contourActorT = vtk.vtkActor()
contourActorT.SetMapper(contourMapperT)
contourActorT.GetProperty().SetColor(1,1,1)

outlineT = vtk.vtkOutlineFilter()
outlineT.SetInputData(input)

outlineMapperT = vtk.vtkPolyDataMapper()
outlineMapperT.SetInputConnection(outlineT.GetOutputPort())

outlineActorT = vtk.vtkActor()
outlineActorT.SetMapper(outlineMapperT)

# Time the execution of the filter w/out scalar tree
CG_timer = vtk.vtkExecutionTimer()
CG_timer.SetFilter(cf)
cf.UseScalarTreeOff()
cf.Update()
CG = CG_timer.GetElapsedWallClockTime()
print ("Contour Grid (no Scalar Tree):", CG)

# Time the execution of the filter w/ simple scalar tree
CG_timer0 = vtk.vtkExecutionTimer()
CG_timer0.SetFilter(cf)
cf.UseScalarTreeOn()
cf.SetScalarTree(sTree)
cf.Update()
CG0 = CG_timer0.GetElapsedWallClockTime()
print ("Contour Grid (build & execute Simple Scalar Tree):", CG0)
Example #7
0
    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;
def create_frog_actor(frog_fn, frog_tissue_fn, tissue, flying_edges, decimate, lut):
    # Get the tissue parameters
    pixel_size = tissue['PIXEL_SIZE']
    columns = tissue['COLUMNS']
    rows = tissue['ROWS']

    voi = tissue['VOI']
    spacing = float(tissue['SPACING'])
    start_slice = float(tissue['START_SLICE'])
    data_spacing = [pixel_size, pixel_size, spacing]
    data_origin = [-(columns / 2.0) * pixel_size, -(rows / 2.0) * pixel_size, start_slice * spacing]

    #
    # adjust y bounds for PNM coordinate system
    #
    tmp = voi[2]
    voi[2] = rows - voi[3] - 1
    voi[3] = rows - tmp - 1

    if tissue['NAME'] == 'skin':
        fn = frog_fn
    else:
        fn = frog_tissue_fn

    reader = vtk.vtkMetaImageReader()
    reader.SetFileName(str(fn))
    reader.SetDataSpacing(data_spacing)
    reader.SetDataOrigin(data_origin)
    reader.SetDataExtent(voi)
    reader.Update()

    last_connection = reader

    if not tissue['NAME'] == 'skin':
        if tissue['ISLAND_REPLACE'] >= 0:
            island_remover = vtk.vtkImageIslandRemoval2D()
            island_remover.SetAreaThreshold(tissue['ISLAND_AREA'])
            island_remover.SetIslandValue(tissue['ISLAND_REPLACE'])
            island_remover.SetReplaceValue(tissue['TISSUE'])
            island_remover.SetInput(last_connection.GetOutput())
            island_remover.Update()
            last_connection = island_remover

        select_tissue = vtk.vtkImageThreshold()
        select_tissue.ThresholdBetween(tissue['TISSUE'], tissue['TISSUE'])
        select_tissue.SetInValue(255)
        select_tissue.SetOutValue(0)
        select_tissue.SetInputConnection(last_connection.GetOutputPort())
        last_connection = select_tissue

    shrinker = vtk.vtkImageShrink3D()
    shrinker.SetInputConnection(last_connection.GetOutputPort())
    shrinker.SetShrinkFactors(tissue['SAMPLE_RATE'])
    shrinker.AveragingOn()
    last_connection = shrinker

    if not all(v == 0 for v in tissue['GAUSSIAN_STANDARD_DEVIATION']):
        gaussian = vtk.vtkImageGaussianSmooth()
        gaussian.SetStandardDeviation(*tissue['GAUSSIAN_STANDARD_DEVIATION'])
        gaussian.SetRadiusFactors(*tissue['GAUSSIAN_RADIUS_FACTORS'])
        gaussian.SetInputConnection(shrinker.GetOutputPort())
        last_connection = gaussian
    # Time the isocontouring.
    ict = collections.defaultdict()
    iso_value = tissue['VALUE']
    if flying_edges:
        iso_surface = vtk.vtkFlyingEdges3D()
        iso_surface.SetInputConnection(last_connection.GetOutputPort())
        iso_surface.ComputeScalarsOff()
        iso_surface.ComputeGradientsOff()
        iso_surface.ComputeNormalsOff()
        iso_surface.SetValue(0, iso_value)
        timer = vtk.vtkExecutionTimer()
        timer.SetFilter(iso_surface)
        iso_surface.Update()
        ict['Flying Edges'] = timer.GetElapsedWallClockTime()
    else:
        iso_surface = vtk.vtkMarchingCubes()
        iso_surface.SetInputConnection(last_connection.GetOutputPort())
        iso_surface.ComputeScalarsOff()
        iso_surface.ComputeGradientsOff()
        iso_surface.ComputeNormalsOff()
        iso_surface.SetValue(0, iso_value)
        timer = vtk.vtkExecutionTimer()
        timer.SetFilter(iso_surface)
        iso_surface.Update()
        ict['Marching Cubes'] = timer.GetElapsedWallClockTime()

    so = SliceOrder()
    # transform = so.get(tissue['SLICE_ORDER'])
    # Match Frog.py
    transform = so.get('hfap')
    transform.Scale(1, -1, 1)
    tf = vtk.vtkTransformPolyDataFilter()
    tf.SetTransform(transform)
    tf.SetInputConnection(iso_surface.GetOutputPort())
    last_connection = tf

    if decimate:
        decimator = vtk.vtkDecimatePro()
        decimator.SetInputConnection(last_connection.GetOutputPort())
        decimator.SetFeatureAngle(tissue['DECIMATE_ANGLE'])
        decimator.MaximumIterations = tissue['DECIMATE_ITERATIONS']
        decimator.PreserveTopologyOn()
        decimator.SetErrorIsAbsolute(1)
        decimator.SetAbsoluteError(tissue['DECIMATE_ERROR'])
        decimator.SetTargetReduction(tissue['DECIMATE_REDUCTION'])
        last_connection = decimator

    smoother = vtk.vtkWindowedSincPolyDataFilter()
    smoother.SetInputConnection(last_connection.GetOutputPort())
    smoother.SetNumberOfIterations(tissue['SMOOTH_ITERATIONS'])
    smoother.BoundarySmoothingOff()
    smoother.FeatureEdgeSmoothingOff()
    smoother.SetFeatureAngle(tissue['SMOOTH_ANGLE'])
    smoother.SetPassBand(tissue['SMOOTH_FACTOR'])
    smoother.NonManifoldSmoothingOn()
    smoother.NormalizeCoordinatesOff()
    smoother.Update()

    normals = vtk.vtkPolyDataNormals()
    normals.SetInputConnection(smoother.GetOutputPort())
    normals.SetFeatureAngle(tissue['FEATURE_ANGLE'])

    stripper = vtk.vtkStripper()
    stripper.SetInputConnection(normals.GetOutputPort())

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

    # Create iso-surface
    contour = vtk.vtkContourFilter()
    contour.SetInputConnection(reader.GetOutputPort())
    contour.SetValue(0, iso_value)

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetOpacity(tissue['OPACITY'])
    actor.GetProperty().SetDiffuseColor(lut.GetTableValue(tissue['TISSUE'])[:3])
    actor.GetProperty().SetSpecular(0.5)
    actor.GetProperty().SetSpecularPower(10)

    return ict, actor
Example #9
0
 def Add_EneActors(self, ren, renWin, iren, ASDdata):
     import numpy as np
     import vtk
     #-----------------------------------------------------------------------
     # Initialize variables
     #-----------------------------------------------------------------------
     ASDEneActors.timer_count = 0
     ASDEneActors.camera_pos = np.zeros(3, dtype=np.float32)
     ASDEneActors.camera_focal = np.zeros(3, dtype=np.float32)
     ASDEneActors.camera_yaw = 0.0
     ASDEneActors.camera_roll = 0.0
     ASDEneActors.camera_pitch = 0.0
     ASDEneActors.camera_azimuth = 0.0
     ASDEneActors.camera_elevation = 0.0
     ASDEneActors.cluster_disp = ASDdata.cluster_flag
     #-----------------------------------------------------------------------
     # 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:
         self.lut = vtk.vtkLookupTable(
         )  ## Lookup table to assign color to the actors
         num_colors = 256
         self.lut.SetNumberOfTableValues(num_colors)
         self.transfer_func = vtk.vtkColorTransferFunction(
         )  ## Function to map data to the colormap
         self.transfer_func.SetColorSpaceToDiverging()
         self.transfer_func.AddRGBPoint(0, 0.230, 0.299, 0.754)
         self.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 = self.transfer_func.GetColor(ss)
             self.lut.SetTableValue(ii, cc[0], cc[1], cc[2], 1.0)
         self.lut.Build()
     else:
         self.lut = vtk.vtkLookupTable(
         )  ## Lookup table to assign color to the actors
         num_colors = 256
         self.lut.SetNumberOfTableValues(num_colors)
         self.transfer_func = vtk.vtkColorTransferFunction(
         )  ## Function to map data to the colormap
         self.transfer_func.SetColorSpaceToDiverging()
         self.transfer_func.AddRGBPoint(-0, 0.230, 0.299, 0.754)
         self.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 = self.transfer_func.GetColor(ss)
             self.lut.SetTableValue(ii, cc[0], cc[1], cc[2], 1.0)
         self.lut.Build()
     #-----------------------------------------------------------------------
     # Data structures for the generation of the smooth grid
     #-----------------------------------------------------------------------
     # Passing the data from the full system to the PolyData
     ASDEneActors.src = vtk.vtkPolyData()
     ASDEneActors.src.SetPoints(ASDdata.coord)
     ASDEneActors.src.GetPointData().SetScalars(ASDdata.energies[0])
     ASDEneActors.scalar_range = ASDEneActors.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 boudings
     # this is mostly useful if splatters are used
     (ASDEneActors.xmin, ASDEneActors.xmax, ASDEneActors.ymin,
      ASDEneActors.ymax, ASDEneActors.zmin,
      ASDEneActors.zmax) = ASDEneActors.src.GetBounds()
     if ASDEneActors.xmin == ASDEneActors.xmax:
         ASDEneActors.xmin = 0.0
         ASDEneActors.xmax = 1.0
     if ASDEneActors.ymin == ASDEneActors.ymax:
         ASDEneActors.ymin = 0.0
         ASDEneActors.ymax = 1.0
     if ASDEneActors.zmin == ASDEneActors.zmax:
         ASDEneActors.zmin = 0.0
         ASDEneActors.zmax = 1.0
     ASDEneActors.xmid = (ASDEneActors.xmin + ASDEneActors.xmax) * 0.5
     ASDEneActors.ymid = (ASDEneActors.ymin + ASDEneActors.ymax) * 0.5
     ASDEneActors.zmid = (ASDEneActors.zmin + ASDEneActors.zmax) * 0.5
     ASDEneActors.height = max(ASDEneActors.xmax, ASDEneActors.ymax,
                               ASDEneActors.zmax) * 1.75
     self.dist_x = np.absolute(
         ASDEneActors.xmax - ASDEneActors.xmin
     )  ## Auxiliary data to find max distance in the x-direction
     self.dist_y = np.absolute(
         ASDEneActors.ymax - ASDEneActors.ymin
     )  ## Auxiliary data to find max distance in the y-direction
     self.dist_z = np.absolute(
         ASDEneActors.zmax - ASDEneActors.zmin
     )  ## Auxiliary data to find max distance in the z-direction
     ASDEneActors.camera_pos[0] = ASDEneActors.xmid
     ASDEneActors.camera_pos[1] = ASDEneActors.ymid
     ASDEneActors.camera_pos[2] = ASDEneActors.height
     ASDEneActors.camera_focal[0] = ASDEneActors.xmid
     ASDEneActors.camera_focal[1] = ASDEneActors.ymid
     ASDEneActors.camera_focal[2] = ASDEneActors.zmid
     # The delaunay tesellation 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
         ASDEneActors.EneDensMethod = vtk.vtkDelaunay2D()
         ASDEneActors.EneDensMethod.SetInputData(ASDEneActors.src)
         ASDEneActors.EneDensMethod.BoundingTriangulationOff()
         ASDEneActors.EneDensMethod.SetTolerance(0.005)
         # Time the execution of the delaunay tessellation
         SM_timer = vtk.vtkExecutionTimer()
         SM_timer.SetFilter(ASDEneActors.EneDensMethod)
         ASDEneActors.EneDensMethod.Update()
         SM = SM_timer.GetElapsedWallClockTime()
         print("2D Delaunay:", SM)
         # Creating the mapper for the smooth surfaces
         ASDEneActors.EneDensMap = vtk.vtkDataSetMapper()
         ASDEneActors.EneDensMap.SetScalarRange(ASDEneActors.scalar_range)
         ASDEneActors.EneDensMap.SetInputConnection(
             ASDEneActors.EneDensMethod.GetOutputPort())
         ASDEneActors.EneDensMap.SetLookupTable(self.lut)
         ASDEneActors.EneDensMap.SetColorModeToMapScalars()
         ASDEneActors.EneDensMap.Update()
         # Creating the actor for the smooth surfaces
         ASDEneActors.EneDensActor = vtk.vtkLODActor()
         ASDEneActors.EneDensActor.SetMapper(ASDEneActors.EneDensMap)
         ASDEneActors.EneDensActor.GetProperty().SetOpacity(0.75)
         ASDEneActors.EneDensActor.GetProperty().EdgeVisibilityOff()
     else:
         #-------------------------------------------------------------------
         # Setting the parameters for the visualization of 3D structures with
         # splatters
         #-------------------------------------------------------------------
         ASDEneActors.EneDensMethod = vtk.vtkShepardMethod()
         ASDEneActors.EneDensMethod.SetInputData(ASDEneActors.src)
         ASDEneActors.EneDensMethod.SetModelBounds(
             ASDEneActors.xmin, ASDEneActors.xmax, ASDEneActors.ymin,
             ASDEneActors.ymax, ASDEneActors.zmin, ASDEneActors.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):
             ASDEneActors.EneDensMethod.SetSampleDimensions(
                 3, int(ASDEneActors.ymax), int(ASDEneActors.zmax))
         elif self.dist_y == min(self.dist_x, self.dist_y, self.dist_z):
             ASDEneActors.EneDensMethod.SetSampleDimensions(
                 int(ASDEneActors.xmax), 3, int(ASDEneActors.zmax))
         elif self.dist_z == min(self.dist_x, self.dist_y, self.dist_z):
             ASDEneActors.EneDensMethod.SetSampleDimensions(
                 int(ASDEneActors.xmax), int(ASDEneActors.ymax), 3)
         # This parameter determines how far in the sample (normalized to 1) the
         # method will look to interpolate, greatly affects performance
         ASDEneActors.EneDensMethod.SetMaximumDistance(0.1)
         # Time the execution of the checkerboard splatter
         SP_timer = vtk.vtkExecutionTimer()
         SP_timer.SetFilter(ASDEneActors.EneDensMethod)
         ASDEneActors.EneDensMethod.Update()
         SP = SP_timer.GetElapsedWallClockTime()
         print("3D Shepard Method:", SP)
         # Mapper for the image obtained from the 3D reconstruction method
         ASDEneActors.EneDensMap = vtk.vtkSmartVolumeMapper()
         ASDEneActors.EneDensMap.SetBlendModeToComposite()
         ASDEneActors.EneDensMap.SetInputConnection(
             ASDEneActors.EneDensMethod.GetOutputPort())
         # Function for the opacity gradient
         volumeGradientOpacity = vtk.vtkPiecewiseFunction()
         volumeGradientOpacity.AddPoint(-1, 0.25)
         volumeGradientOpacity.AddPoint(0.5, 0.75)
         volumeGradientOpacity.AddPoint(1.0, 1.0)
         # Properties of the volume to be rendered
         ASDEneActors.volumeProperty = vtk.vtkVolumeProperty()
         ASDEneActors.volumeProperty.SetInterpolationType(1)
         ASDEneActors.volumeProperty.SetColor(self.transfer_func)
         ASDEneActors.volumeProperty.SetAmbient(0.6)
         ASDEneActors.volumeProperty.SetDiffuse(0.6)
         ASDEneActors.volumeProperty.SetSpecular(0.1)
         ASDEneActors.volumeProperty.SetGradientOpacity(
             volumeGradientOpacity)
         # Volume actor, this works in a different way than LOD actors
         ASDEneActors.EneDensActor = vtk.vtkVolume()
         ASDEneActors.EneDensActor.SetMapper(ASDEneActors.EneDensMap)
         ASDEneActors.EneDensActor.SetProperty(self.volumeProperty)
     #-----------------------------------------------------------------------
     # Energy spheres
     #-----------------------------------------------------------------------
     ASDEneActors.EneAtom = vtk.vtkSphereSource()
     ASDEneActors.EneAtom.SetRadius(0.50)
     ASDEneActors.EneAtom.SetThetaResolution(10)
     ASDEneActors.EneAtom.SetPhiResolution(10)
     #-----------------------------------------------------------------------
     # Set the mapper for the energies
     #-----------------------------------------------------------------------
     ASDEneActors.EneMapper = vtk.vtkGlyph3DMapper()
     ASDEneActors.EneMapper.SetSourceConnection(
         ASDEneActors.EneAtom.GetOutputPort())
     ASDEneActors.EneMapper.SetInputData(ASDEneActors.src)
     ASDEneActors.EneMapper.SetScalarRange(ASDEneActors.scalar_range)
     ASDEneActors.EneMapper.SetScaleFactor(1.00)
     ASDEneActors.EneMapper.SetScaleModeToNoDataScaling()
     ASDEneActors.EneMapper.SetLookupTable(self.lut)
     ASDEneActors.EneMapper.SetColorModeToMapScalars()
     ASDEneActors.EneMapper.Update()
     #-----------------------------------------------------------------------
     # Energy actors
     #-----------------------------------------------------------------------
     ASDEneActors.EneActor = vtk.vtkLODActor()
     ASDEneActors.EneActor.SetMapper(ASDEneActors.EneMapper)
     ASDEneActors.EneActor.GetProperty().SetSpecular(0.3)
     ASDEneActors.EneActor.GetProperty().SetSpecularPower(60)
     ASDEneActors.EneActor.GetProperty().SetAmbient(0.2)
     ASDEneActors.EneActor.GetProperty().SetDiffuse(0.8)
     ASDEneActors.EneActor.VisibilityOff()
     #-----------------------------------------------------------------------
     # Setting information of the renderer
     #-----------------------------------------------------------------------
     # Define the renderer
     # Add the actors to the scene
     if ASDdata.flag2D:
         ren.AddActor(ASDEneActors.EneDensActor)
     else:
         ren.AddViewProp(ASDEneActors.EneDensActor)
     ren.AddActor(ASDEneActors.EneActor)
     # Defining the camera directions
     ren.GetActiveCamera().Azimuth(ASDEneActors.camera_azimuth)
     ren.GetActiveCamera().Elevation(ASDEneActors.camera_elevation)
     ren.GetActiveCamera().Yaw(ASDEneActors.camera_yaw)
     ren.GetActiveCamera().Roll(ASDEneActors.camera_roll)
     ren.GetActiveCamera().Pitch(ASDEneActors.camera_pitch)
     ren.GetActiveCamera().SetFocalPoint(ASDEneActors.camera_focal)
     ren.GetActiveCamera().SetPosition(ASDEneActors.camera_pos)
     ren.GetActiveCamera().SetViewUp(0, 1, 0)
     #-----------------------------------------------------------------------
     # Start the renderer
     #-----------------------------------------------------------------------
     iren.Start()
     renWin.Render()
     return
Example #10
0
    def AddASD_actors(self, ren, renWin, mode, viz_type, iren):
        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

        ASD_data = ASDVTKReading.ASDReading()
        # Add the data structures with regards to reading the data
        ASD_data.ReadingWrapper(mode=mode, viz_type=viz_type)

        ASDMomActors.kmc_disp = ASD_data.kmc_flag
        ASDMomActors.cluster_disp = ASD_data.cluster_flag
        ########################################################################
        # Data structures for the generation of the smooth grid
        ########################################################################
        ASDMomActors.glob_flag_2D = ASD_data.flag_2D
        ASDMomActors.glob_color_x = ASD_data.selected_colors_x
        ASDMomActors.glob_color_y = ASD_data.selected_colors_y
        ASDMomActors.glob_color_z = ASD_data.selected_colors_z
        ########################################################################
        # 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 ASDMomActors.glob_flag_2D:
            self.lut = vtk.vtkLookupTable()
            num_colors = 256
            self.lut.SetNumberOfTableValues(num_colors)

            self.transfer_func = vtk.vtkColorTransferFunction()
            self.transfer_func.SetColorSpaceToDiverging()
            self.transfer_func.AddRGBPoint(0, 0.230, 0.299, 0.754)
            self.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 = self.transfer_func.GetColor(ss)
                self.lut.SetTableValue(ii, cc[0], cc[1], cc[2], 1.0)
            self.lut.Build()
        else:
            self.lut = vtk.vtkLookupTable()
            num_colors = 256
            self.lut.SetNumberOfTableValues(num_colors)

            self.transfer_func = vtk.vtkColorTransferFunction()
            self.transfer_func.SetColorSpaceToDiverging()
            self.transfer_func.AddRGBPoint(-0, 0.230, 0.299, 0.754)
            self.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 = self.transfer_func.GetColor(ss)
            self.lut.SetTableValue(ii, cc[0], cc[1], cc[2], 1.0)
        self.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(ASD_data.selected_points)
        ASDMomActors.src.GetPointData().SetScalars(ASD_data.selected_colors_z)
        ASDMomActors.src.GetPointData().SetVectors(ASD_data.selected_vectors)
        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 boudings
        # 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 tesellation 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 ASDMomActors.glob_flag_2D:
            # Passing the data to generate a triangulation of the data
            MagDensMethod = vtk.vtkDelaunay2D()
            MagDensMethod.SetInputData(ASDMomActors.src)
            MagDensMethod.BoundingTriangulationOff()
            MagDensMethod.SetTolerance(0.005)
            # Time the execution of the delaunay tessellation
            SM_timer = vtk.vtkExecutionTimer()
            SM_timer.SetFilter(MagDensMethod)
            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(
                MagDensMethod.GetOutputPort())
            ASDMomActors.MagDensMap.SetLookupTable(self.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()

        else:
            ####################################################################
            # Setting the parameters for the visualization of 3D structures with
            # splatters
            ####################################################################
            MagDensMethod = vtk.vtkShepardMethod()
            MagDensMethod.SetInputData(ASDMomActors.src)
            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):
                MagDensMethod.SetSampleDimensions(3, int(ASDMomActors.ymax),
                                                  int(ASDMomActors.zmax))
            elif self.dist_y == min(self.dist_x, self.dist_y, self.dist_z):
                MagDensMethod.SetSampleDimensions(int(ASDMomActors.xmax), 3,
                                                  int(ASDMomActors.zmax))
            elif self.dist_z == min(self.dist_x, self.dist_y, self.dist_z):
                MagDensMethod.SetSampleDimensions(int(ASDMomActors.xmax),
                                                  int(ASDMomActors.ymax), 3)
    # This parameter determines how far in the sample (normalized to 1) the
    # method will look to interpolate, greatly affects performance
            MagDensMethod.SetMaximumDistance(0.1)

            # Time the execution of the checkerboard splatter
            SP_timer = vtk.vtkExecutionTimer()
            SP_timer.SetFilter(MagDensMethod)
            MagDensMethod.Update()
            SP = SP_timer.GetElapsedWallClockTime()
            print("3D Shepard Method:", SP)

            # Mapper for the image obtained from the 3D reconstruction method
            ASDMomActors.MagDensMap = vtk.vtkSmartVolumeMapper()
            ASDMomActors.MagDensMap.SetBlendModeToComposite()
            ASDMomActors.MagDensMap.SetInputConnection(
                MagDensMethod.GetOutputPort())

            # Function for the opacity gradient
            volumeGradientOpacity = vtk.vtkPiecewiseFunction()
            volumeGradientOpacity.AddPoint(-1, 0.25)
            volumeGradientOpacity.AddPoint(0.5, 0.75)
            volumeGradientOpacity.AddPoint(1.0, 1.0)

            # Properties of the volume to be rendered
            ASDMomActors.volumeProperty = vtk.vtkVolumeProperty()
            ASDMomActors.volumeProperty.SetInterpolationType(1)
            ASDMomActors.volumeProperty.SetColor(self.transfer_func)
            ASDMomActors.volumeProperty.SetAmbient(0.6)
            ASDMomActors.volumeProperty.SetDiffuse(0.6)
            ASDMomActors.volumeProperty.SetSpecular(0.1)
            ASDMomActors.volumeProperty.SetGradientOpacity(
                volumeGradientOpacity)
            #volumeProperty.ShadeOn()

            # Volume actor, this works in a different way than LOD actors
            ASDMomActors.MagDensActor = vtk.vtkVolume()
            ASDMomActors.MagDensActor.SetMapper(ASDMomActors.MagDensMap)
            ASDMomActors.MagDensActor.SetProperty(self.volumeProperty)

    ####################################################################
    # Alternative rendering methods
    ####################################################################
    # The checkerboard splatter method, much faster than the Shepard method
    # however, it seems to change the values of the scalars embeded in the
    # point data which results in incorrect diplay of the magnetization
    #cbdSplatter = vtk.vtkCheckerboardSplatter()
    #cbdSplatter.ScalarWarpingOff()
    #cbdSplatter.SetFootprint(2)
    #cbdSplatter.SetExponentFactor(-5)
    #cbdSplatter.SetParallelSplatCrossover(2)
    #cbdSplatter.SetOutputScalarTypeToDouble()
    #cbdSplatter.CappingOn()
    #cbdSplatter.ScalarWarpingOn()
    #cbdSplatter.SetRadius(1)

    # 3D delaunay method, the far superior as it conserves the shape of the
    # sample, however it is extremely slow, with a rendering of a 3D image
    # taking several minutes
    #smooth_loop = vtk.vtkDelaunay3D()
    #smooth_loop.SetInputData(self.src)
    #smooth_loop.SetTolerance(0.01)
    #smooth_loop.SetAlpha(2)
    #smooth_loop.AlphaTrisOff()
    #smooth_loop.Update()

    ########################################################################
    # Data structures for the spins
    ########################################################################
    # Passing the data from the full system to the PolyData
        ASDMomActors.src_spins = vtk.vtkPolyData()
        ASDMomActors.src_spins.SetPoints(ASD_data.selected_points)
        ASDMomActors.src_spins.GetPointData().SetScalars(
            ASD_data.selected_colors_z)
        ASDMomActors.src_spins.GetPointData().SetVectors(
            ASD_data.selected_vectors)
        scalar_range_spins = ASDMomActors.src_spins.GetScalarRange()
        ########################################################################
        # Data structures for the contours
        ########################################################################
        # Define the contour filters
        contours = vtk.vtkContourFilter()
        contours.SetInputConnection(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()

        ########################################################################
        # Data structures for the impurity cluster
        ########################################################################
        if ASD_data.cluster_flag:

            # Passing the data from the cluster to the PolyData
            src_clus = vtk.vtkPolyData()
            src_clus.SetPoints(ASD_data.coord_c)
            src_clus.GetPointData().SetScalars(ASD_data.colors_clus)

            # Passing the data from the selected impurities
            src_imp = vtk.vtkPolyData()
            src_imp.SetPoints(ASD_data.points_clus_imp)
            src_imp.GetPointData().SetScalars(ASD_data.colors_imp)
            src_imp.Modified()

            atomSource = vtk.vtkDelaunay2D()
            atomSource.SetInputData(src_clus)
            atomSource.BoundingTriangulationOff()
            atomSource.SetTolerance(0.05)
            atomSource.Update()

            smoothFilter = vtk.vtkSmoothPolyDataFilter()
            smoothFilter.SetInputConnection(atomSource.GetOutputPort())
            smoothFilter.SetNumberOfIterations(5)
            smoothFilter.SetRelaxationFactor(0.1)
            smoothFilter.FeatureEdgeSmoothingOff()
            smoothFilter.BoundarySmoothingOn()
            smoothFilter.Update()

            # Creating the mapper for the smooth surfaces
            atomMapper = vtk.vtkDataSetMapper()
            atomMapper.SetScalarRange(scalar_range)
            atomMapper.SetInputConnection(smoothFilter.GetOutputPort())
            atomMapper.SetColorMode(2)
            atomMapper.Update()

            # Creating the actor for the smooth surfaces
            ASDMomActors.atom = vtk.vtkLODActor()
            ASDMomActors.atom.SetMapper(atomMapper)
            ASDMomActors.atom.GetProperty().EdgeVisibilityOff()
            ASDMomActors.atom.GetProperty().SetSpecularPower(30)
            ASDMomActors.atom.GetProperty().SetAmbient(0.2)
            ASDMomActors.atom.GetProperty().SetDiffuse(0.8)
            ASDMomActors.atom.GetProperty().SetOpacity(0.50)

            # 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
            ASDMomActors.atom_imp = vtk.vtkLODActor()
            ASDMomActors.atom_imp.SetMapper(atomMapper_imp)
            ASDMomActors.atom_imp.GetProperty().SetSpecular(0.3)
            ASDMomActors.atom_imp.GetProperty().SetSpecularPower(30)
            ASDMomActors.atom_imp.GetProperty().SetAmbient(0.2)
            ASDMomActors.atom_imp.GetProperty().SetDiffuse(0.8)

    ########################################################################
    # 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)
        ASDMomActors.Spins.VisibilityOff()

        ########################################################################
        # Creation of the data structures for the data clipping
        ########################################################################
        # Right now this only can clip polydata, which is fine for 2D structures
        # however, for the 3d delaunay tesellation, the output is an unstructured
        # grid, which means that annother type of clipper is required
        ASDMomActors.plane = vtk.vtkPlane()
        ASDMomActors.plane.SetOrigin(ASDMomActors.xmin, ASDMomActors.ymid, 0)
        ASDMomActors.plane.SetNormal(1, 0, 0)
        if ASDMomActors.glob_flag_2D:
            self.clipper = vtk.vtkClipPolyData()
            self.clipper.SetInputConnection(MagDensMethod.GetOutputPort())
            self.clipper.SetClipFunction(ASDMomActors.plane)
            self.clipper.InsideOutOn()

            ASDMomActors.clipperMapper = vtk.vtkPolyDataMapper()
            ASDMomActors.clipperMapper.SetInputConnection(
                self.clipper.GetOutputPort())
            ASDMomActors.clipperMapper.SetLookupTable(self.lut)

            ASDMomActors.clipperActor = vtk.vtkLODActor()
            ASDMomActors.clipperActor.SetMapper(ASDMomActors.clipperMapper)
            ASDMomActors.clipperActor.VisibilityOff()
        else:
            self.clipper = vtk.vtkClipVolume()
            self.clipper.SetInputConnection(MagDensMethod.GetOutputPort())
            self.clipper.SetClipFunction(ASDMomActors.plane)
            self.clipper.InsideOutOn()

            ASDMomActors.clipperMapper = vtk.vtkDataSetMapper()
            ASDMomActors.clipperMapper.SetInputConnection(
                self.clipper.GetOutputPort())
            ASDMomActors.clipperMapper.SetLookupTable(self.transfer_func)

            ASDMomActors.clipperActor = vtk.vtkActor()
            ASDMomActors.clipperActor.SetMapper(ASDMomActors.clipperMapper)
            ASDMomActors.clipperActor.GetProperty().SetOpacity(1.00)

        if (ASD_data.kmc_flag):
            ########################################################################
            # Setting data structures for the KMC particle visualization
            ########################################################################
            ASDMomActors.KMC_src = vtk.vtkPolyData()
            ASDMomActors.KMC_src.SetPoints(ASD_data.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 the information for the axes widget
        ########################################################################
        # Create the axes actor
        axes = vtk.vtkAxesActor()
        axes.SetShaftTypeToCylinder()
        axes.SetCylinderRadius(0.05)
        axes.SetNormalizedShaftLength(0.9, 0.9, 0.9)
        axes.SetNormalizedTipLength(0.40, 0.40, 0.40)
        # The properties of the text can be controlled independently
        axes.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetColor(
            0.0, 0.0, 0.0)
        axes.GetYAxisCaptionActor2D().GetCaptionTextProperty().SetColor(
            0.0, 0.0, 0.0)
        axes.GetZAxisCaptionActor2D().GetCaptionTextProperty().SetColor(
            0.0, 0.0, 0.0)
        axes.GetXAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff()
        axes.GetYAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff()
        axes.GetZAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff()

        # The axes actor is then used as an orientation marker widget, the advantage
        # of setting it up as a widget is that it is interactive and one can move it
        # and that it moves as the zoom changes
        # Must make sure that the widget is part of the main class so that it can
        # be actually rendered and no segfaults occurr
        ASDMomActors.OrientMarker = vtk.vtkOrientationMarkerWidget()
        ASDMomActors.OrientMarker.SetOutlineColor(0.9300, 0.5700, 0.1300)
        ASDMomActors.OrientMarker.SetOrientationMarker(axes)
        ASDMomActors.OrientMarker.SetViewport(0.0, 0.0, 0.3, 0.3)

        ########################################################################
        # Setting the information for the scalar bar widget
        ########################################################################
        # Create the scalar bar actor
        ASDMomActors.scalar_bar = vtk.vtkScalarBarActor()
        if ASDMomActors.glob_flag_2D:
            ASDMomActors.scalar_bar.SetLookupTable(
                ASDMomActors.MagDensMap.GetLookupTable())
        else:
            ASDMomActors.scalar_bar.SetLookupTable(self.transfer_func)

        ASDMomActors.scalar_bar.GetLabelTextProperty().SetColor(0.0, 0.0, 0.0)
        ASDMomActors.scalar_bar.SetNumberOfLabels(5)
        ASDMomActors.scalar_bar.GetLabelTextProperty().ShadowOff()
        ASDMomActors.scalar_bar.GetLabelTextProperty().BoldOff()
        ASDMomActors.scalar_bar.GetLabelTextProperty().ItalicOff()
        ASDMomActors.scalar_bar.SetLabelFormat("%-#6.1f")
        ASDMomActors.scalar_bar.SetBarRatio(0.5)

        # Create the scalar_bar_widget
        ASDMomActors.scalar_bar_widget = vtk.vtkScalarBarWidget()
        ASDMomActors.scalar_bar_widget.SetScalarBarActor(
            ASDMomActors.scalar_bar)

        # Representation to actually control where the scalar bar is
        scalarBarRep = ASDMomActors.scalar_bar_widget.GetRepresentation()
        scalarBarRep.SetOrientation(0)  # 0 = Horizontal, 1 = Vertical
        scalarBarRep.GetPositionCoordinate().SetValue(0.30, 0.05)
        scalarBarRep.GetPosition2Coordinate().SetValue(0.50, 0.05)

        ########################################################################
        # Setting information of the renderer
        ########################################################################
        # Define the renderer
        # Add the actors to the scene
        if ASDMomActors.glob_flag_2D:
            ren.AddActor(ASDMomActors.MagDensActor)
        else:
            ren.AddViewProp(ASDMomActors.MagDensActor)

        ren.AddActor(ASDMomActors.Spins)
        ren.AddActor(ASDMomActors.vector)
        ren.AddActor(ASDMomActors.contActor)
        ren.AddActor(self.clipperActor)

        # If there is information about the cluster add the needed actors
        if ASD_data.cluster_flag:
            ren.AddActor(ASDMomActors.atom)
            ren.AddActor(ASDMomActors.atom_imp)

    #If the KMC particles are present add them to the renderer
        if ASD_data.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(self.camera_focal)
        ren.GetActiveCamera().SetPosition(self.camera_pos)
        ren.GetActiveCamera().SetViewUp(0, 1, 0)
        # Must make sure the widgets is called before the renderer is called
        # Scalar bar
        ASDMomActors.scalar_bar_widget.SetInteractor(iren)
        ASDMomActors.scalar_bar_widget.On()
        # Orient marker
        ASDMomActors.OrientMarker.SetInteractor(iren)
        ASDMomActors.OrientMarker.SetEnabled(1)
        ########################################################################
        # Start the renderer
        ########################################################################
        iren.Start()
        renWin.Render()

        return