示例#1
0
def run(filename=None):
    """Create a dummy pipeline and save the coprocessing state in the filename
        specified, if any, else dumps it out on stdout."""

    from paraview import simple, servermanager
    simple.LoadDistributedPlugin("CatalystScriptGeneratorPlugin")
    wavelet = simple.Wavelet(registrationName="Wavelet1")
    contour = simple.Contour()
    display = simple.Show()
    view = simple.Render()
    # create a new 'Parallel PolyData Writer'
    parallelPolyDataWriter0 = simple.ParallelPolyDataWriter()

    viewname = servermanager.ProxyManager().GetProxyName("views", view.SMProxy)
    script = DumpPipeline(
        export_rendering=True,
        simulation_input_map={"Wavelet1": "input"},
        screenshot_info={viewname: ['image.png', '1', '1', '2', '400', '400']})
    if filename:
        f = open(filename, "w")
        f.write(script)
        f.close()
    else:
        print "# *** Generated Script Begin ***"
        print script
        print "# *** Generated Script End ***"
示例#2
0
def sample(dataDir, outputDir):
    convert(os.path.join(dataDir, 'Data/bot2.wrl'), outputDir, True, True)
    convert(os.path.join(dataDir, 'Data/can.ex2'), outputDir)
    convert(os.path.join(dataDir, 'Data/can.ex2'), outputDir, True, True,
            'can_MS.ex2')
    convert(os.path.join(dataDir, 'Data/can.ex2'), outputDir, True, False,
            'can_M.ex2')
    convert(os.path.join(dataDir, 'Data/can.ex2'), outputDir, False, True,
            'can_S.ex2')
    convert(os.path.join(dataDir, 'Data/disk_out_ref.ex2'), outputDir, True,
            False, 'disk_out_ref_M.ex2')
    convert(os.path.join(dataDir, 'Data/disk_out_ref.ex2'), outputDir)
    convert(os.path.join(dataDir, 'Data/RectGrid2.vtk'), outputDir)

    # Create image data based on the Wavelet source
    wavelet = simple.Wavelet()
    wavelet.UpdatePipeline()
    imageData = wavelet.GetClientSideObject().GetOutputDataObject(0)
    writeDataSet('Wavelet.vti', imageData, outputDir)

    # Create a table based on the disk_out_ref
    diskout = simple.ExtractSurface(
        simple.MergeBlocks(
            simple.OpenDataFile(os.path.join(dataDir,
                                             'Data/disk_out_ref.ex2'))))
    diskout.UpdatePipeline()
    unstructuredGrid = diskout.GetClientSideObject().GetOutputDataObject(0)
    table = vtkTable()
    _nbFields = unstructuredGrid.GetPointData().GetNumberOfArrays()
    for i in range(_nbFields):
        table.AddColumn(unstructuredGrid.GetPointData().GetArray(i))
    writeDataSet('table', table, outputDir)
def test():
    w = simple.Wavelet()

    dataRange = [40.0, 270.0]
    arrayName = ('POINT_DATA', 'RTData')
    fileGenerator = FileNameGenerator(
        '/tmp/iso', '{contourBy}_{contourValue}_{theta}_{phi}.jpg')

    cExplorer = ContourExplorer(fileGenerator, w, arrayName, dataRange, 25)
    proxy = cExplorer.getContour()
    rep = simple.Show(proxy)

    lut = simple.GetLookupTableForArray("RTData",
                                        1,
                                        RGBPoints=[
                                            43.34006881713867, 0.23, 0.299,
                                            0.754, 160.01158714294434, 0.865,
                                            0.865, 0.865, 276.68310546875,
                                            0.706, 0.016, 0.15
                                        ])
    rep.LookupTable = lut
    rep.ColorArrayName = arrayName
    view = simple.Render()

    exp = ThreeSixtyImageStackExporter(fileGenerator, view, [0, 0, 0], 100,
                                       [0, 0, 1], [30, 45])
    for progress in cExplorer:
        exp.UpdatePipeline()
        print progress
def run(filename=None):
    """Create a dummy pipeline and save the coprocessing state in the filename
    specified, if any, else dumps it out on stdout."""

    from paraview import simple, servermanager
    wavelet = simple.Wavelet(registrationName="Wavelet1")
    contour = simple.Contour()
    script = DumpCoProcessingScript(export_rendering=False,
                                    simulation_input_map={"Wavelet1": "input"},
                                    screenshot_info={},
                                    rescale_data_range=True,
                                    enable_live_viz=True,
                                    filename=filename)
    if not filename:
        print "# *** Generated Script Begin ***"
        print script
        print "# *** Generated Script End ***"
def test2():
    w = simple.Wavelet()
    c = simple.Contour(ComputeScalars=1, Isosurfaces=range(50, 250, 10))
    r = simple.Show(c)

    lut = simple.GetLookupTableForArray("RTData",
                                        1,
                                        RGBPoints=[
                                            43.34006881713867, 0.23, 0.299,
                                            0.754, 160.01158714294434, 0.865,
                                            0.865, 0.865, 276.68310546875,
                                            0.706, 0.016, 0.15
                                        ])
    r.LookupTable = lut
    r.ColorArrayName = ('POINT_DATA', 'RTData')

    view = simple.Render()
    exp = ThreeSixtyImageStackExporter(
        FileNameGenerator('/tmp/z', 'w_{theta}_{phi}.jpg'), view, [0, 0, 0],
        100, [0, 0, 1], [10, 20])
    exp.UpdatePipeline()
    exp = ThreeSixtyImageStackExporter(
        FileNameGenerator('/tmp/y', 'cone_{theta}_{phi}.jpg'), view, [0, 0, 0],
        100, [0, 1, 0], [10, 20])
    exp.UpdatePipeline()
    exp = ThreeSixtyImageStackExporter(
        FileNameGenerator('/tmp/x', 'cone_{theta}_{phi}.jpg'), view, [0, 0, 0],
        100, [1, 0, 0], [10, 20])
    exp.UpdatePipeline()
    simple.ResetCamera()
    simple.Hide(c)
    slice = SliceExplorer(
        FileNameGenerator('/tmp/slice', 'w_{sliceColor}_{slicePosition}.jpg'),
        view, w, {"RTData": {
            "lut": lut,
            "type": 'POINT_DATA'
        }}, 50, [0, 1, 0])
    slice.UpdatePipeline()
def test3():
    w = simple.Wavelet()
    points_series = [ { "name": "Diagonal" , "probes": [ [ float(x), float(x), float(x) ] for x in range(-10, 10)] }, \
                      { "name": "Slice", "probes": [ [ float(x), float(y), 0.0 ] for x in range(-10, 10) for y in range(-10, 10)] } ]
    time_serie = [{
        "name": "Origin",
        "probe": [0.0, 0.0, 0.0]
    }, {
        "name": "FaceCenter",
        "probe": [10.0, 0.0, 0.0]
    }]

    prober = DataProber(
        FileNameGenerator('/tmp/dataprober',
                          'data_{time}_{field}_{serie}.csv'), w, points_series,
        ["RTData"])
    prober.UpdatePipeline(0.0)

    timeProber = TimeSerieDataProber(
        FileNameGenerator('/tmp/dataprober_time', 'data_{field}.csv'), w,
        time_serie, ["RTData"], 100)
    for time in range(101):
        timeProber.UpdatePipeline(time)
示例#7
0
# -----------------------------------------------------------------------------
# User configuration
# -----------------------------------------------------------------------------
outputDir = '/Users/seb/Desktop/float-image/'
# -----------------------------------------------------------------------------

from paraview import simple
from paraview.web.dataset_builder import *

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

wavelet = simple.Wavelet()
calc = simple.Calculator()
calc.Function = 'coordsX'
calc.ResultArrayName = 'x'
contour = simple.Contour(PointMergeMethod="Uniform Binning",
                         ComputeScalars=1,
                         ComputeNormals=1,
                         Isosurfaces=157.09,
                         ContourBy=['POINTS', 'RTData'])
clip = simple.Clip()
clip.ClipType.Normal = [0.0, 0.0, -1.0]

# -----------------------------------------------------------------------------
# Data To Export
# -----------------------------------------------------------------------------

layerMesh = {
    'core1': False,
示例#8
0
    def test_contour(self):
        pv.Connect()  # using a dedicated server state for each test
        print "\nTEST_CONTOUR"

        # set up some processing task
        view_proxy = pv.CreateRenderView()
        view_proxy.OrientationAxesVisibility = 0
        view_proxy.ViewSize = [1024, 768]
        s = pv.Wavelet()
        contour = pv.Contour(Input=s, ContourBy='RTData', ComputeScalars=1)
        sliceRep = pv.Show(contour)

        # make or open a cinema data store to put results in
        fname = "/tmp/test_pv_contour/info.json"
        cs = file_store.FileStore(fname)
        cs.add_metadata({'type': 'parametric-image-stack'})
        cs.add_metadata({'store_type': 'FS'})
        cs.add_metadata({'version': '0.0'})
        cs.filename_pattern = "{phi}_{theta}_{contour}_{color}_contour.png"
        cs.add_parameter(
            "phi", store.make_parameter('phi', [90, 120, 140]))
        cs.add_parameter(
            "theta", store.make_parameter('theta', [-90, -30, 30, 90]))
        cs.add_parameter(
            "contour",
            store.make_parameter('contour', [50, 100, 150, 200]))
        cs.add_parameter(
            "color",
            store.make_parameter(
                'color', ['white', 'RTData_1'], typechoice='list'))

        # associate control points with parameters of the data store
        cam = pv_explorers.Camera(
            [0, 0, 0], [0, 1, 0], 75.0, view_proxy)
        filt = pv_explorers.Contour("contour", contour)

        colorChoice = pv_explorers.ColorList()
        colorChoice.AddSolidColor('white', [1, 1, 1])
        colorChoice.AddLUT('POINTS', 'RTData_1', 'X')
        col = pv_explorers.Color("color", colorChoice, sliceRep)

        params = ["phi", "theta", "contour", "color"]
        e = pv_explorers.ImageExplorer(
            cs, params, [cam, filt, col], view_proxy)

        # run through all parameter combinations and put data into the store
        e.explore()

        # Reproduce an entry and compare vs. loaded

        # First set the parameters to reproduce
        cam.execute(store.Document({'theta': 30, 'phi': 140}))
        filt.execute(store.Document({'contour': 100}))
        col.execute(store.Document({'color': 'RTData_1'}))

        imageslice = ch.pvRenderToArray(view_proxy)

        # Now load the corresponding
        cs2 = file_store.FileStore(fname)
        cs2.load()
        docs = []
        for doc in cs2.find(
                {'theta': 30, 'phi': 140,
                 'contour': 100, 'color': 'RTData_1'}):
            docs.append(doc.data)

        # compare the two
        l2error = ch.compare_l2(imageslice, docs[0])
        ncc = ch.compare_ncc(imageslice, docs[0])
        success = (l2error < 1.0) and (ncc > 0.99)
        if not success:
            print "\n l2-error = ", l2error, " ; ncc = ", ncc, "\n"
        self.assertTrue(success)
        pv.Disconnect()  # using a dedicated server state for each test
示例#9
0
    def test_composite(self):
        pv.Connect()  # get a new context like a normal script would
        print "\nTEST_COMPOSITE"

        # set up some processing task
        view_proxy = pv.CreateRenderView()
        view_proxy.OrientationAxesVisibility = 0
        s = pv.Wavelet()
        contour = pv.Contour(Input=s, ContourBy='RTData', ComputeScalars=1)
        sliceRep = pv.Show(contour)

        # make or open a cinema data store to put results in
        fname = "/tmp/test_pv_composite/info.json"
        cs = file_store.FileStore(fname)
        cs.add_metadata({'type': 'composite-image-stack'})
        cs.add_metadata({'store_type': 'FS'})
        cs.add_metadata({'version': '0.1'})

        cs.filename_pattern = "results.png"
        cs.add_parameter(
            "phi", store.make_parameter('phi', [90, 120, 140]))
        cs.add_parameter(
            "theta", store.make_parameter('theta', [-90, -30, 30, 90]))
        cs.add_layer(
            "vis", store.make_parameter("vis", ['contour']))
        contours = [50, 100, 150, 200]
        cs.add_control("isoval",
                       store.make_parameter('isoval', contours))
        cs.assign_parameter_dependence("isoval", "vis", ['contour'])
        cs.add_field("color",
                     store.make_field('color',
                                      {'white': 'rgb',
                                       'depth': 'depth',
                                       'lum': 'luminance',
                                       'RTData_1': 'lut'},),
                     "isoval", contours)

        # associate control points with parameters of the data store
        cam = pv_explorers.Camera([0, 0, 0], [0, 1, 0], 75.0, view_proxy)
        showcontour = pv_explorers.SourceProxyInLayer("contour",
                                                      sliceRep, contour)
        layertrack = explorers.Layer("vis", [showcontour])
        filt = pv_explorers.Contour("isoval", contour)

        # additional specification necessary for the color field
        colorChoice = pv_explorers.ColorList()
        colorChoice.AddSolidColor('white', [1, 1, 1])
        colorChoice.AddLUT('POINTS', 'RTData_1', 'X')
        colorChoice.AddDepth('depth')
        colorChoice.AddLuminance('lum')

        col = pv_explorers.Color("color", colorChoice, sliceRep)

        paramNames = ["phi", "theta", "vis", "isoval", "color"]
        trackList = [cam, layertrack, filt, col]
        e = pv_explorers.ImageExplorer(cs,
                                       paramNames, trackList, view_proxy)

        # run through all parameter combinations and put data into the store
        e.explore()

        # Reproduce an entry and compare vs. loaded
        # First set the parameters to reproduce
        cam.execute(store.Document({'theta': 30, 'phi': 140}))
        filt.execute(store.Document({'isoval': 100}))
        col.execute(store.Document({'color': 'RTData_1'}))
        imageslice = ch.pvRenderToArray(view_proxy)

        # Now load the corresponding
        cs2 = file_store.FileStore(fname)
        cs2.load()
        docs = []
        for doc in cs2.find({'theta': 30, 'phi': 140,
                             'isoval': 100, 'color': 'RTData_1'}):
            docs.append(doc.data)

        # compare the two
        l2error = ch.compare_l2(imageslice, docs[0])
        ncc = ch.compare_ncc(imageslice, docs[0])
        success = (l2error < 1.0) and (ncc > 0.99)

        if not success:
            print "\n l2-error = ", l2error, " ; ncc = ", ncc, "\n"

        self.assertTrue(success)
        pv.Disconnect()  # using a dedicated server state for each test
try:
    numsteps = int(sys.argv[2])
except ValueError:
    print('the last argument should be a number')
    numsteps = 10

#imageData2 = vtk.vtkImageData()

for step in range(numsteps):
    print("Timestep %d" % step)
    # assume simulation time starts at 0
    time = step / float(numsteps)

    # create the input to the coprocessing library.  normally
    # this will come from the adaptor
    wavelet = pvsimple.Wavelet()
    wholeExtent = wavelet.WholeExtent
    # put in some variation in the point data that changes with time
    wavelet.Maximum = 255 + 200 * math.sin(step * math.pi / 100)
    wavelet.UpdatePipeline()
    imageData = pvsimple.servermanager.Fetch(wavelet)

    # note that we delete wavelet now since.  if not, it will
    # get deleted automatically in the coprocessing script
    pvsimple.Delete(wavelet)
    wavelet = None

    # "perform" coprocessing.  results are outputted only if
    # the passed in script says we should at time/step
    coProcess(imageData, time, step, sys.argv[1], wholeExtent)
    imageData = None
示例#11
0
from paraview import simple
from paraview import smtesting
from paraview import data_exploration as cinema

smtesting.ProcessCommandLineArguments()
work_directory = os.path.join(smtesting.TempDir, 'cinema')
has_rgbz_view = True

try:
    simple.LoadDistributedPlugin('RGBZView', ns=globals())
except:
    has_rgbz_view = False

# === Data to explore and configuration =======================================

data_to_explore = simple.Wavelet()
min = 63.96153259277344
max = 250.22056579589844
center_of_rotation = [0.0, 0.0, 0.0]
rotation_axis = [0.0, 0.0, 1.0]
angle_steps = (72, 60)
distance = 60
lut = simple.GetLookupTableForArray("RTData",
                                    1,
                                    RGBPoints=[
                                        min, 0.23, 0.299, 0.754,
                                        (min + max) * 0.5, 0.865, 0.865, 0.865,
                                        max, 0.706, 0.016, 0.15
                                    ],
                                    ColorSpace='Diverging',
                                    ScalarRangeInitialized=1.0)
from paraview import simple
from tonic.paraview.data_writer import *

ds = simple.Wavelet()

dataRenderer = ScalarRenderer()

view = dataRenderer.getView()
view.ViewSize = [500, 500]

simple.Show(ds, view)
simple.ResetCamera(view)

dataRenderer.writeArray('/Users/seb/Desktop/composite/', ds, 'RTData')