Exemplo n.º 1
0
    def __init__(self, module_manager):
        # initialise our base class
        ModuleBase.__init__(self, module_manager)


        self._shepardFilter = vtk.vtkShepardMethod()
        
        module_utils.setup_vtk_object_progress(self, self._shepardFilter,
                                           'Applying Shepard Method.')
        
                                           
        self._config.maximum_distance = 1.0
        
                                           
                                           

        configList = [
            ('Kernel size:', 'kernelSize', 'tuple:int,3', 'text',
             'Size of the kernel in x,y,z dimensions.')]

        ScriptedConfigModuleMixin.__init__(
            self, configList,
            {'Module (self)' : self,
             'vtkImageContinuousDilate3D' : self._imageDilate})

        self.sync_module_logic_with_config()
Exemplo n.º 2
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkShepardMethod(), 'Processing.',
         ('vtkDataSet',), ('vtkImageData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
Exemplo n.º 3
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkShepardMethod(),
                                       'Processing.', ('vtkDataSet', ),
                                       ('vtkImageData', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
Exemplo n.º 4
0
    def __init__(self, module_manager):
        # initialise our base class
        ModuleBase.__init__(self, module_manager)

        self._shepardFilter = vtk.vtkShepardMethod()

        module_utils.setup_vtk_object_progress(self, self._shepardFilter,
                                               'Applying Shepard Method.')

        self._config.maximum_distance = 1.0

        configList = [('Kernel size:', 'kernelSize', 'tuple:int,3', 'text',
                       'Size of the kernel in x,y,z dimensions.')]

        ScriptedConfigModuleMixin.__init__(
            self, configList, {
                'Module (self)': self,
                'vtkImageContinuousDilate3D': self._imageDilate
            })

        self.sync_module_logic_with_config()
Exemplo n.º 5
0
    points.InsertPoint(i, math.Random(0, 1), math.Random(0, 1),
                       math.Random(0, 1))
    i = i + 1

scalars = vtk.vtkFloatArray()
i = 0
while i < 50:
    scalars.InsertValue(i, math.Random(0, 1))
    i = i + 1

profile = vtk.vtkPolyData()
profile.SetPoints(points)
profile.GetPointData().SetScalars(scalars)
# triangulate them
#
shepard = vtk.vtkShepardMethod()
shepard.SetInputData(profile)
shepard.SetModelBounds(0, 1, 0, 1, .1, .5)
#    shepard SetMaximumDistance .1
shepard.SetNullValue(1)
shepard.SetSampleDimensions(20, 20, 20)
shepard.Update()
map = vtk.vtkDataSetMapper()
map.SetInputConnection(shepard.GetOutputPort())
block = vtk.vtkActor()
block.SetMapper(map)
block.GetProperty().SetColor(1, 0, 0)
# Add the actors to the renderer, set the background and size
#
ren1.AddActor(block)
ren1.SetBackground(1, 1, 1)
Exemplo n.º 6
0
scalars.InsertValue(10, 20)
scalars.InsertValue(11, 20)
scalars.InsertValue(12, 40)
scalars.InsertValue(13, 20)
scalars.InsertValue(14, 20)

profile = vtk.vtkPolyData()
profile.SetPoints(points)
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())
scalars.InsertValue(10, 20)
scalars.InsertValue(11, 20)
scalars.InsertValue(12, 40)
scalars.InsertValue(13, 20)
scalars.InsertValue(14, 20)

profile = vtk.vtkPolyData()
profile.SetPoints(points)
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())
Exemplo n.º 8
0
import vtk
from vtkMETAPython import vtkVis15DatasetReader

rd = vtkVis15DatasetReader()
#rd.SetFileName("ds14_scivis_0128_e4_dt04_0.2000.txt")
#rd.SetFileName("/home/csunix/scsdjd/Public/ds14_scivis_0128_e4_dt04_0.0600.txt")
rd.SetFileName("/usr/not-backed-up/ds14_scivis_0128_e4_dt04_0.0600.txt")
rd.Update()
bnds = rd.GetOutput().GetPoints().GetBounds()

ass = vtk.vtkAssignAttribute()
ass.SetInputConnection(rd.GetOutputPort())
ass.Assign("phi", "SCALARS", "POINT_DATA")


shep = vtk.vtkShepardMethod()
shep.SetInputConnection(ass.GetOutputPort())
shep.SetSampleDimensions(100,100,100)
shep.SetMaximumDistance(0.1)
shep.SetModelBounds(bnds)


print "Running Shepard."
shep.Update()
print "Shep completed."
so = shep.GetOutput()
print so
sd = so.GetPointData()
for i in range(0,sd.GetNumberOfArrays()):
  ar = sd.GetArray(i)
  print i, "\t", ar.GetName(), "\t", ar.GetRange()
Exemplo n.º 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
Exemplo n.º 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