Esempio n. 1
0
    def load(self, path):
        vtk = ps.LegacyVTKReader(FileNames=[str(path)])
        ps.RenameSource(" ", vtk)
        name = self._get_postfix(path)
        data = self._threshold_vtk(vtk, name)

        self._data = data
        self._rename(name)
        self.show()
Esempio n. 2
0
 def getSolidMask(self, scale=4):
     sampling = [
         v * scale if v > 1 else 1 for v in self.domain['dimensions']
     ]
     filePath = os.path.join(self.workdir, 'SandTank.vtk')
     solidGeometry = simple.LegacyVTKReader(FileNames=[filePath])
     solidImage = simple.ResampleToImage(
         Input=solidGeometry,
         SamplingBounds=self.domain['bounds'],
         SamplingDimensions=sampling)
     solidImage.UpdatePipeline()
     mask = solidImage.GetClientSideObject().GetOutput().GetPointData(
     ).GetArray('vtkValidPointMask')
     return {
         'scale': scale,
         'array': self.addAttachment(buffer(mask).tobytes()),
     }
Esempio n. 3
0
    def __init__(self, filename):
        """Open the data source.

        Args:
            filename (str): Name of the file to be opened.
        """

        if not os.path.isfile(filename):
            raise ValueError("File %s does not exist" % filename)

        extension = os.path.splitext(filename)[1].lower()
        if extension == ".vtk":
            self.reader = pvs.LegacyVTKReader(FileNames=[filename])
        elif extension in [".foam", ".openfoam"]:
            self.reader = pvs.OpenFOAMReader(FileName=filename)
            self.reader.UpdatePipeline(time=self.reader.TimestepValues[-1])
        else:
            raise ValueError("Unsupported format: %s" % extension)

        self.fullpath = os.path.abspath(filename)
Esempio n. 4
0
def display_data(prefix,
                 data_dir,
                 render_view,
                 label,
                 color_func,
                 representation='Surface'):
    reader = pvs.LegacyVTKReader(FileNames=get_sample_fnames(prefix, data_dir),
                                 registrationName=label)
    display = pvs.Show(reader, render_view)
    display.Representation = representation
    display.ColorArrayName = ['CELLS', label]
    display.LookupTable = color_func
    display.ScaleFactor = 50.0
    display.SelectScaleArray = label
    display.GlyphTableIndexArray = label
    display.UseSeparateColorMap = True
    #print(dir(display))
    color_bar = pvs.GetScalarBar(color_func, render_view)
    color_bar.Title = label
    color_bar.ComponentTitle = ''
    color_bar.ScalarBarLength = 0.12
    display.SetScalarBarVisibility(render_view, True)
Esempio n. 5
0
x = np.array(refData[:, 0])
y = np.array(refData[:, 1])
z = np.array(refData[:, 2])

refResponses = {}
for i in range(np.size(header) - 3):
    refResponses[header[i + 3]] = refData[:, i + 3]
simResponses = {}
for name in refResponses.iterkeys():
    simResponses[name] = []

fname = os.getcwd() + '/' + filename[0]

extension = os.path.splitext(filename[0])[1]
if extension == '.vtk':
    solution = s.LegacyVTKReader(guiName="solution", FileNames=[fname])
elif extension == '.vtu':
    solution = s.XMLUnstructuredGridReader(guiName="solution",
                                           FileName=[fname])
else:
    print "= - Unknown file format of type: ", extension

for i in range(np.size(x)):
    temp = []
    ProbeLocation1 = []
    ProbeLocation1 = s.ProbeLocation(guiName="ProbeLocation1",
                                     ProbeType="Fixed Radius Point Source",
                                     Input=solution)
    ProbeLocation1.ProbeType.Center = [x[i], y[i], z[i]]
    temp = s.servermanager.Fetch(ProbeLocation1)
    for name in refResponses.iterkeys():
def batchVis(c1File,particleFile,step,saveAs):
    """Renders a bijel top down view in paraview and saves a screenshot."""
    import paraview.simple as pv
    # visualize a vtk file 
    c1 = pv.LegacyVTKReader(FileNames=c1File)
    p = pv.LegacyVTKReader(FileNames=particleFile)
    renderView1 = pv.GetActiveViewOrCreate('RenderView')
    renderView1.ViewSize = [1298, 860]
    renderView1.Background = [1.0, 1.0, 1.0]
    renderView1.InteractionMode = '2D'
    pDisplay = pv.Show(p, renderView1)
    c1Display = pv.Show(c1, renderView1)

    # create particle glyphs
    glyph = pv.Glyph(Input=p,GlyphType="Sphere")
    glyph.ScaleFactor = 1.0
    glyph.GlyphMode = 'All Points'
    glyph.GlyphType.Radius = 1.0
    glyph.GlyphType.ThetaResolution = 20
    glyph.GlyphType.PhiResolution = 20
    glyph.Scalars = ['POINTS','radius']
    glyph.Vectors = ['POINTS','None']
    glyph.ScaleMode = 'scalar'

    # show data in view
    glyphDisplay = pv.Show(glyph, renderView1)
    pv.ColorBy(glyphDisplay, None)
    pv.SetActiveSource(c1)
    pv.ColorBy(c1Display, ('POINTS', 'c1'))
    c1Display.RescaleTransferFunctionToDataRange(True)
    c1Display.SetRepresentationType('Volume')

    # make box outline
    # box = pv.Box()
    # box.XLength = 128.0
    # box.YLength = 128.0
    # box.ZLength = 64.0
    # box.Center = [64.0, 64.0, 32.0]
    # boxDisplay = pv.Show(box, renderView1)
    # boxDisplay.SetRepresentationType('Outline')
    # boxDisplay.AmbientColor = [0.0, 0.0, 0.0]

    # set coloring of c1
    c1LUT = pv.GetColorTransferFunction('c1')
    c1LUT.RGBPoints = [0.006000000052154064, 0.231373, 0.298039, 0.752941, 0.5120000033639371, 0.865003, 0.865003, 0.865003, 1.0180000066757202, 0.705882, 0.0156863, 0.14902]
    c1LUT.ColorSpace = 'Diverging'
    c1LUT.BelowRangeColor = [0.0, 0.0, 0.0]
    c1LUT.AboveRangeColor = [1.0, 1.0, 1.0]
    c1LUT.NanColor = [1.0, 1.0, 0.0]
    c1LUT.Discretize = 1
    c1LUT.NumberOfTableValues = 256
    c1LUT.ScalarRangeInitialized = 1.0
    c1LUT.AllowDuplicateScalars = 1

    c1PWF = pv.GetOpacityTransferFunction('c1')
    c1PWF.Points = [0.0, 0.05, 0.5, 0.0, 0.3, 0.05, 0.5, 0.0, 0.4, 0.5, 0.5, 0.0, 0.6, 0.5, 0.5, 0.0, 0.7, 0.05, 0.5, 0.0, 1., 0.05, 0.5, 0.0]

    # annotate time step in rendering
    # text = pv.Text
    # text.Text = 'Step '+str(step)
    # textDisplay = pv.Show(text,renderView1)
    # textDisplay.Color = [0.0, 0.0, 0.0]
    # textDisplay.WindowLocation = 'UpperCenter'

    # reset view to fit data
    renderView1.ResetCamera()
    # pv.Render()

    # save screen shot
    viewLayout1 = pv.GetLayout()
    print(saveAs)
    pv.SaveScreenshot(saveAs, layout=viewLayout1, magnification=1, quality=100)

    # clean up
    # pv.Delete(box)
    pv.Delete(glyph)
    pv.Delete(p)
    pv.Delete(c1)
    del c1
    del p
    del glyph
Esempio n. 7
0
        else:
            allFiles.append(fullPath)

    return allFiles


fileList = getListOfFiles('../postProcessing/cuttingPlanes/')
fileList = [el for el in fileList if '.vtk' in el]
'''
directory='../postProcessing/triangulatedCuttingPlanes'
if not os.path.exists(directory):
    os.makedirs(directory)
'''

for i in range(0, len(fileList)):
    pvdata = pvs.LegacyVTKReader(FileNames=fileList[i])
    clean1 = pvs.Clean(Input=pvdata)
    clean1.PieceInvariant = 0
    clean1.AbsoluteTolerance = 0.0000001
    clean1.ToleranceIsAbsolute = 1
    clean1.ConvertLinesToPoints = 0
    clean1.ConvertPolysToLines = 0
    clean1.ConvertStripsToPolys = 0
    triang = pvs.Triangulate(Input=clean1)
    pvs.SaveData(filename=os.path.join(
        '../postProcessing/triangulatedCuttingPlanes/', '{}_{}{}'.format(
            (os.path.splitext(os.path.basename(fileList[i]))[0]),
            os.path.basename(os.path.dirname(fileList[i])),
            (os.path.splitext(os.path.basename(fileList[i]))[1]))),
                 proxy=triang,
                 FileType='Ascii')