Пример #1
0
    def processFile(self):
        self._download_mesh_file()

        reader = simple.OpenDataFile(_MeshViewer.meshFile)
        reader.UpdatePipeline()
        self.outline = simple.Show(reader)
        self.outline.Representation = 'Outline'

        # Get information about cell data arrays
        nbFaces = 0
        cdInfo = reader.GetCellDataInformation()
        numberOfCellArrays = cdInfo.GetNumberOfArrays()
        for idx in xrange(numberOfCellArrays):
            array = cdInfo.GetArray(idx)
            if array.GetName() != 'modelfaceids':
                continue
            nbFaces = int(array.GetRange(-1)[1])

        # Extract each face and keep representation around
        _MeshViewer.faces = []
        for idx in range(nbFaces):
            threshold = simple.Threshold(Scalars=['CELLS', 'modelfaceids'],
                                         Input=reader,
                                         ThresholdRange=[idx, idx])
            rep = simple.Show(threshold)
            _MeshViewer.faces.append(rep)

        self.view = simple.Render()
        self.view.Background = [0, 0, 0]
Пример #2
0
    def reload_models(self):
        self._clean_vizard_models()

        # Apply clip filter
        data = self._apply_clip(self.vtk_data)

        # Iterate over every material
        material_range = self.vtk_data_local.GetCellData().GetArray(
            cfg.material_name).GetRange()
        for material in range(int(material_range[0]),
                              int(material_range[1]) + 1):
            # Separate the data by material
            material_data = pv.Threshold(Input=data)
            self._filters += [material_data]
            # Settings are generated mostly by ParaView Trace function
            material_data.Scalars = ['CELLS', cfg.material_name]
            material_data.ThresholdRange = [material, material]

            # Generate cloud
            local = pv.servermanager.Fetch(material_data)
            self.cloud_materials[material] = self.generate_cloud(
                local, cfg.coloring_name)
            self.cloud_materials[material].setParent(self.cloud_node)

            # Apply ExtractSurface and Triangulate filter
            extractSurface = pv.ExtractSurface(Input=material_data)
            self._filters += [extractSurface]
            # Settings are generated by ParaView Trace function
            extractSurface.PieceInvariant = 1
            extractSurface.NonlinearSubdivisionLevel = 1
            triangulate = pv.Triangulate(Input=extractSurface)
            self._filters += [triangulate]

            # Generate surface
            local = pv.servermanager.Fetch(triangulate)
            self.surface_materials[material] = self.generate_surface(
                local, cfg.coloring_name)
            self.surface_materials[material].setParent(self.surface_node)
Пример #3
0
from paraview import simple
from paraview.web.dataset_builder import *

# -----------------------------------------------------------------------------
# Pipeline creation
# -----------------------------------------------------------------------------

core = simple.OpenDataFile(earthCore)
coreSurface = simple.ExtractSurface(Input=core)
coreWithNormals = simple.GenerateSurfaceNormals(Input=coreSurface)

reader = simple.OpenDataFile(inputFile % time[0])
reader.CellArrayStatus = ['temperature', 'salinity']

dataCleanUp = simple.Threshold(Input=reader,
                               Scalars=['CELLS', 'temperature'],
                               ThresholdRange=[-1000.0, 50.0])
dataToPoints = simple.CellDatatoPointData(Input=dataCleanUp)

sceneDescription = {
    'size': [500, 500],
    'light': ['intensity', 'normal'],
    'camera': {
        'CameraViewUp': [0.0, 0.0, 1.0],
        'CameraPosition': [107823.5, -28000000, -44044.25],
        'CameraFocalPoint': [107823.5, -7766.0, -44044.25]
    },
    'scene': [{
        'name': 'Earth',
        'source': coreWithNormals,
        'colors': {
Пример #4
0
 def _threshold_vtk(self, vtk, name):
     threshold = ps.Threshold(Input=vtk)
     threshold.Scalars = ["POINTS", name]
     threshold.ThresholdRange = self._get_range(vtk)
     return threshold
Пример #5
0
def get_curvatures(vtk_file, vtk_file_dir, output_file, output_file_dir,
                   arr_name, sample_rate, gauss_filter, mean_filter):
    import paraview.simple as ps
    import numpy as np
    import paraview as pv
    from vtk.util.numpy_support import vtk_to_numpy

    # have paraview open the vtk data file
    reader = ps.OpenDataFile(vtk_file_dir + vtk_file)
    sys_data = pv.servermanager.Fetch(reader)
    nx, ny, nz = sys_data.GetDimensions()
    dx, dy, dz = sys_data.GetSpacing()

    # downsample the data (makes for a smoother contour surface)
    ds = ps.ExtractSubset(reader)
    ds.SampleRateI = sample_rate
    ds.SampleRateJ = sample_rate
    ds.SampleRateK = sample_rate
    ds.VOI[1] = nx - 1
    ds.VOI[3] = ny - 1
    ds.VOI[5] = nz - 1
    ds.IncludeBoundary = 1
    ds.UpdatePipeline()

    # have paraview apply a contour surface at a concentration value of cont_val
    contour = ps.Contour(ds)
    cont_val = 0.0  # this might change depending on order parameter
    contour.ContourBy = ['POINTS',
                         arr_name]  # Viz is the name of the vtk array
    contour.Isosurfaces = [cont_val]
    contour.SetPropertyWithName('ComputeNormals', 0)
    contour.UpdatePipeline()

    # have paraview calculate the curvature (default is Gaussian)
    curvature = ps.Curvature(contour)

    # filter the curvatures
    threshold = ps.Threshold(curvature)
    threshold.Scalars = ['POINTS', 'Gauss_Curvature']
    threshold.ThresholdRange = [-gauss_filter, gauss_filter]
    threshold.AllScalars = 1
    threshold.UpdatePipeline()
    gauss_data = pv.servermanager.Fetch(threshold)
    size_gauss = gauss_data.GetPointData().GetArray(0).GetSize()

    # convert vtk array to numpy array
    gauss_curv = vtk_to_numpy(gauss_data.GetPointData().GetArray(0))

    # integrate the surface area and curvature
    summed_curv = ps.IntegrateVariables(threshold)
    summed_curv_data = pv.servermanager.Fetch(summed_curv)
    g_surf_area = summed_curv_data.GetCellData().GetArray(0).GetValue(0)

    # have paraview recalculate the mean curvature
    curvature.SetPropertyWithName('CurvatureType', 'Mean')
    curvature.UpdatePipeline()
    threshold = ps.Threshold(curvature)
    threshold.Scalars = ['POINTS', 'Mean_Curvature']
    threshold.ThresholdRange = [-mean_filter, mean_filter]
    threshold.UpdatePipeline()
    summed_curv = ps.IntegrateVariables(threshold)
    summed_curv.UpdatePipeline()
    summed_curv_data = pv.servermanager.Fetch(summed_curv)
    m_surf_area = summed_curv_data.GetCellData().GetArray(0).GetValue(0)
    mean_data = pv.servermanager.Fetch(threshold)

    # convert vtk array to numpy array
    mean_curv = vtk_to_numpy(mean_data.GetPointData().GetArray(0))

    # calculate the surface area to volume ratio
    g_surf_to_vol = g_surf_area / (nx * dx * ny * dy * nz * dz)
    m_surf_to_vol = m_surf_area / (nx * dx * ny * dy * nz * dz)

    # calculate percent of data used in threshold
    curvature_data = pv.servermanager.Fetch(curvature)
    size_curv = curvature_data.GetPointData().GetArray(0).GetSize()

    # save the numpy arrays for later manipulation
    np.savez(output_file_dir + output_file, gauss_curv, mean_curv,
             g_surf_to_vol, g_surf_area, m_surf_to_vol, m_surf_area)

    # delete paraview sources and filters
    ps.Delete(summed_curv)
    ps.Delete(contour)
    ps.Delete(ds)
    ps.Delete(reader)
    del (sys_data)
    del (summed_curv_data)

    return 0
Пример #6
0
        class Pipeline:

            # Create data source "input" (provides simulation fields)
            simData = coprocessor.CreateProducer(datadescription, "input")

            # Write VTK output if requested
            if writeVtkOutput:
                fullWriter = pvs.XMLHierarchicalBoxDataWriter(
                    Input=simData, DataMode="Appended", CompressorType="ZLib")
                # Set freq=1 to ensure that output is written whenever the pipeline runs
                coprocessor.RegisterWriter(fullWriter,
                                           filename='bg_out_%t.vth',
                                           freq=1)

            # Create a new render view to generate images
            renderView = pvs.CreateView('RenderView')
            renderView.ViewSize = [1500, 768]
            renderView.InteractionMode = '2D'
            renderView.AxesGrid = 'GridAxes3DActor'
            renderView.CenterOfRotation = [2.8, 1.7, 0.0]
            renderView.StereoType = 0
            renderView.CameraPosition = [2.8, 1.7, 10000.0]
            renderView.CameraFocalPoint = [2.8, 1.7, 0.0]
            renderView.CameraParallelScale = 3.386
            renderView.Background = [0.32, 0.34, 0.43]
            renderView.ViewTime = datadescription.GetTime()

            # Show simulation time with 1 digit after decimal point
            annotateTime = pvs.AnnotateTime()
            annotateTime.Format = 'time: %.1f'
            timeDisplay = pvs.Show(annotateTime, renderView)

            # Combine uu and vv components into velocity vector field
            calculatorVelField = pvs.Calculator(Input=simData)
            calculatorVelField.AttributeType = 'Cell Data'
            calculatorVelField.ResultArrayName = 'velocity'
            calculatorVelField.Function = 'uu*iHat+vv*jHat'

            # Compute velocity field magnitudes
            calculatorVelMag = pvs.Calculator(Input=calculatorVelField)
            calculatorVelMag.AttributeType = 'Cell Data'
            calculatorVelMag.ResultArrayName = 'mag'
            calculatorVelMag.Function = 'mag(velocity)'

            # Remove cells with vanishing velocity magnitude
            velMagThreshold = pvs.Threshold(calculatorVelMag)
            velMagThreshold.Scalars = ['CELLS', 'mag']
            velMagThreshold.ThresholdRange = [1.0e-6, 1.0e30]

            # Visualise remaining velocity vector field using arrows with fixed length
            # and skipping cells to avoid crowding
            glyphs = pvs.Glyph(Input=velMagThreshold, GlyphType='Arrow')
            glyphs.Vectors = ['CELLS', 'velocity']
            glyphs.ScaleFactor = 0.2
            glyphs.GlyphMode = 'Every Nth Point'
            glyphs.Stride = 100
            glyphs.GlyphTransform = 'Transform2'

            # Register the view with coprocessor and provide it with information such as
            # the filename to use. Set freq=1 to ensure that images are rendered whenever
            # the pipeline runs
            coprocessor.RegisterView(renderView,
                                     filename='bg_out_%t.png',
                                     freq=1,
                                     fittoscreen=0,
                                     magnification=1,
                                     width=1500,
                                     height=768,
                                     cinema={})

            # Create colour transfer function for field
            LUT = pvs.GetColorTransferFunction('hh')
            LUT.RGBPoints = [
                9.355e-05, 0.231, 0.298, 0.753, 0.0674, 0.865, 0.865, 0.865,
                0.135, 0.706, 0.0157, 0.149
            ]
            LUT.ScalarRangeInitialized = 1.0

            # Render data field and colour by field value using lookup table
            fieldDisplay = pvs.Show(simData, renderView)
            fieldDisplay.Representation = 'Surface'
            fieldDisplay.ColorArrayName = ['CELLS', 'hh']
            fieldDisplay.LookupTable = LUT

            # Add velocity field visualisation
            velfieldDisplay = pvs.Show(glyphs, renderView)