コード例 #1
0
def matplotlib_figure(width, height):
    """Create a Matplotlib figure with specified width and height for rendering.

  w
    Width of desired plot.
  h
    Height of desired plot.

  return
    A Matplotlib figure.
  """
    try:
        from matplotlib.backends.backend_agg import FigureCanvasAgg
    except:
        paraview.print_error(
            "Error: Cannot import matplotlib.backends.backend_agg.FigureCanvasAgg"
        )
    try:
        from matplotlib.figure import Figure
    except:
        paraview.print_error("Error: Cannot import matplotlib.figure.Figure")

    figure = Figure()
    figureCanvas = FigureCanvasAgg(figure)
    figure.set_dpi(72)
    figure.set_size_inches(float(width) / 72.0, float(height) / 72.0)

    return figure
コード例 #2
0
def figure_to_data(figure):
    """
  @brief Convert a Matplotlib figure to a numpy 2D array with RGBA uint8 channels and return it.
  @param figure A matplotlib figure.
  @return A numpy 2D array of RGBA values.
  """
    # Draw the renderer
    try:
        import matplotlib
    except:
        paraview.print_error("Error: Cannot import matplotlib")

    figure.canvas.draw()

    # Get the RGBA buffer from the figure
    w, h = figure.canvas.get_width_height()

    try:
        import numpy
    except:
        paraview.print_error("Error: Cannot import numpy")

    buf = numpy.fromstring(figure.canvas.tostring_argb(), dtype=numpy.uint8)
    buf.shape = (h, w, 4)

    # canvas.tostring_argb gives pixmap in ARGB mode. Roll the alpha channel to have it in RGBA mode
    buf = numpy.roll(buf, 3, axis=2)

    return buf
コード例 #3
0
ファイル: python_view.py プロジェクト: 151706061/ParaView
def figure_to_data(figure):
  """
  @brief Convert a Matplotlib figure to a numpy 2D array with RGBA uint8 channels and return it.
  @param figure A matplotlib figure.
  @return A numpy 2D array of RGBA values.
  """
  # Draw the renderer
  try:
    import matplotlib
  except:
    paraview.print_error("Error: Cannot import matplotlib")

  figure.canvas.draw()

  # Get the RGBA buffer from the figure
  w, h = figure.canvas.get_width_height()

  try:
    import numpy
  except:
    paraview.print_error("Error: Cannot import numpy")

  buf = numpy.fromstring(figure.canvas.tostring_argb(), dtype=numpy.uint8)
  buf.shape = (h, w, 4)

  # canvas.tostring_argb gives pixmap in ARGB mode. Roll the alpha channel to have it in RGBA mode
  buf = numpy.roll(buf, 3, axis=2)

  return buf
コード例 #4
0
ファイル: python_view.py プロジェクト: Kitware/ParaView
def matplotlib_figure(width, height):
  """Create a Matplotlib figure with specified width and height for rendering.

  w
    Width of desired plot.
  h
    Height of desired plot.

  return
    A Matplotlib figure.
  """
  try:
    from matplotlib.backends.backend_agg import FigureCanvasAgg
  except:
    paraview.print_error("Error: Cannot import matplotlib.backends.backend_agg.FigureCanvasAgg")
  try:
    from matplotlib.figure import Figure
  except:
    paraview.print_error("Error: Cannot import matplotlib.figure.Figure")

  figure = Figure()
  figureCanvas = FigureCanvasAgg(figure)
  figure.set_dpi(72)
  figure.set_size_inches(float(width)/72.0, float(height)/72.0)

  return figure
コード例 #5
0
ファイル: simple.py プロジェクト: archels/ParaView
def Connect(ds_host=None, ds_port=11111, rs_host=None, rs_port=11111):
    """Creates a connection to a server. Example usage:
    > Connect("amber") # Connect to a single server at default port
    > Connect("amber", 12345) # Connect to a single server at port 12345
    > Connect("amber", 11111, "vis_cluster", 11111) # connect to data server, render server pair"""
    Disconnect(globals(), False)
    connection = servermanager.Connect(ds_host, ds_port, rs_host, rs_port)
    _add_functions(globals())

    servermanager.ProxyManager().DisableStateUpdateNotification()
    servermanager.ProxyManager().UpdateFromRemote()
    tk = servermanager.ProxyManager().GetProxy("timekeeper", "TimeKeeper")
    if not tk:
       try:
           tk = servermanager.misc.TimeKeeper()
           servermanager.ProxyManager().RegisterProxy("timekeeper", "TimeKeeper", tk)
       except AttributeError:
           paraview.print_error("Error: Could not create TimeKeeper")

    scene = servermanager.ProxyManager().GetProxy("animation", "AnimationScene")
    if not scene:
       try:
           scene = AnimationScene()
           scene.TimeKeeper = tk
       except NameError:
           paraview.print_error("Error: Could not create AnimationScene")

    servermanager.ProxyManager().EnableStateUpdateNotification()
    servermanager.ProxyManager().TriggerStateUpdate()

    return connection
コード例 #6
0
def initialize():
    global coProcessor, usecp
    if usecp:
        import paraview
        import vtkParallelCorePython
        import vtk
        from mpi4py import MPI
        import os, sys

        paraview.options.batch = True
        paraview.options.symmetric = True
        import vtkPVClientServerCoreCorePython as CorePython
        try:
            import vtkPVServerManagerApplicationPython as ApplicationPython
        except:
            paraview.print_error(
                "Error: Cannot import vtkPVServerManagerApplicationPython")

        if not CorePython.vtkProcessModule.GetProcessModule():
            pvoptions = None
            if paraview.options.batch:
                pvoptions = CorePython.vtkPVOptions()
                pvoptions.SetProcessType(CorePython.vtkPVOptions.PVBATCH)
                if paraview.options.symmetric:
                    pvoptions.SetSymmetricMPIMode(True)
            ApplicationPython.vtkInitializationHelper.Initialize(
                sys.executable, CorePython.vtkProcessModule.PROCESS_BATCH,
                pvoptions)

        import paraview.servermanager as pvsm
        # we need ParaView 4.2 since ParaView 4.1 doesn't properly wrap
        # vtkPVPythonCatalystPython
        if pvsm.vtkSMProxyManager.GetVersionMajor() < 4 or (
                pvsm.vtkSMProxyManager.GetVersionMajor() == 4
                and pvsm.vtkSMProxyManager.GetVersionMinor() < 2):
            print 'Must use ParaView v4.2 or greater'
            sys.exit(0)

        import numpy
        import vtkPVCatalystPython as catalyst
        import vtkPVPythonCatalystPython as pythoncatalyst
        import paraview.simple
        import paraview.vtk as vtk
        from paraview import numpy_support
        paraview.options.batch = True
        paraview.options.symmetric = True

        coProcessor = catalyst.vtkCPProcessor()
        pm = paraview.servermanager.vtkProcessModule.GetProcessModule()
        from mpi4py import MPI
コード例 #7
0
def initialize():
    global coProcessor, usecp
    if usecp:
        import paraview
        import vtkParallelCorePython
        import vtk
        from mpi4py import MPI
        import os, sys

        paraview.options.batch = True
        paraview.options.symmetric = True
        import vtkPVClientServerCoreCorePython as CorePython
        try:
            import vtkPVServerManagerApplicationPython as ApplicationPython
        except:
            paraview.print_error("Error: Cannot import vtkPVServerManagerApplicationPython")

        if not CorePython.vtkProcessModule.GetProcessModule():
            pvoptions = None
            if paraview.options.batch:
                pvoptions = CorePython.vtkPVOptions();
                pvoptions.SetProcessType(CorePython.vtkPVOptions.PVBATCH)
                if paraview.options.symmetric:
                    pvoptions.SetSymmetricMPIMode(True)
            ApplicationPython.vtkInitializationHelper.Initialize(sys.executable, CorePython.vtkProcessModule.PROCESS_BATCH, pvoptions)

        import paraview.servermanager as pvsm
        # we need ParaView 4.2 since ParaView 4.1 doesn't properly wrap
        # vtkPVPythonCatalystPython
        if pvsm.vtkSMProxyManager.GetVersionMajor() != 4 or \
           pvsm.vtkSMProxyManager.GetVersionMinor() < 2:
            print 'Must use ParaView v4.2 or greater'
            sys.exit(0)

        import numpy
        import vtkPVCatalystPython as catalyst
        import vtkPVPythonCatalystPython as pythoncatalyst
        import paraview.simple
        import paraview.vtk as vtk
        from paraview import numpy_support
        paraview.options.batch = True
        paraview.options.symmetric = True

        coProcessor = catalyst.vtkCPProcessor()
        pm = paraview.servermanager.vtkProcessModule.GetProcessModule()
        from mpi4py import MPI
コード例 #8
0
def numpy_to_image(numpy_array):
    """Convert a numpy 2D or 3D array to a vtkImageData object.

  numpy_array
    2D or 3D numpy array containing image data

  return
    vtkImageData with the numpy_array content
  """
    try:
        import numpy
    except:
        paraview.print_error("Error: Cannot import numpy")

    shape = numpy_array.shape
    if len(shape) < 2:
        raise Exception('numpy array must have dimensionality of at least 2')

    h, w = shape[0], shape[1]
    c = 1
    if len(shape) == 3:
        c = shape[2]

    # Reshape 2D image to 1D array suitable for conversion to a
    # vtkArray with numpy_support.numpy_to_vtk()
    linear_array = numpy.reshape(numpy_array, (w * h, c))

    try:
        from vtkmodules.util import numpy_support
    except:
        paraview.print_error(
            "Error: Cannot import vtkmodules.util.numpy_support")

    vtk_array = numpy_support.numpy_to_vtk(linear_array)

    image = vtkImageData()
    image.SetDimensions(w, h, 1)
    image.AllocateScalars(vtk_array.GetDataType(), 4)
    image.GetPointData().GetScalars().DeepCopy(vtk_array)

    return image
コード例 #9
0
ファイル: TestFetchData.py プロジェクト: xj361685640/ParaView
def TestFetchDataRanks(producer, ranks, allGather=False):
    print_info("TestFetchDataRanks %s" % repr(ranks))
    dataMap = FetchData(producer,
                        SourceRanks=ranks,
                        GatherOnAllRanks=allGather)

    if not allGather and GetIsSymmetric() and GetRank() > 0:
        # dataMap must be empty.
        if dataMap:
            print_error("FetchData should not deliver any data on satellites!")
            return False
    else:
        dataRanks = [x for x in dataMap.keys()]
        expectedRanks = []

        numRanks = GetNumberOfRanks()
        for r in ranks:
            if r < numRanks:
                expectedRanks.append(r)

        if dataRanks != expectedRanks:
            print_error("ranks mismatch %s != %s", repr(dataRanks),
                        repr(expectedRanks))
            return False

        # ensure we got valid data from all ranks
        for rank, data in dataMap.items():
            if not ValidateData(producer, data):
                print_error("bad data from rank %d", rank)
                return False
    return True
コード例 #10
0
ファイル: TestFetchData.py プロジェクト: xj361685640/ParaView
def TestFetchDataBasic(producer, allGather=False):
    print_info("TestFetchDataBasic")
    dataMap = FetchData(producer, GatherOnAllRanks=allGather)

    if not allGather and GetIsSymmetric() and GetRank() > 0:
        # dataMap must be empty.
        if dataMap:
            print_error("FetchData should not deliver any data on satellites!")
            return False
    else:
        dataRanks = [x for x in dataMap.keys()]

        # ensure we got data from all rank.
        numRanks = GetNumberOfRanks()

        if len(dataRanks) != numRanks:
            print_error("rank mismatch len(%s) != %d", repr(dataRanks),
                        numRanks)
            return False

        # ensure we got valid data from all ranks
        for rank, data in dataMap.items():
            if not ValidateData(producer, data):
                print_error("bad data from rank %d", rank)
                return False

    return True
コード例 #11
0
ファイル: python_view.py プロジェクト: Kitware/ParaView
def numpy_to_image(numpy_array):
  """Convert a numpy 2D or 3D array to a vtkImageData object.

  numpy_array
    2D or 3D numpy array containing image data

  return
    vtkImageData with the numpy_array content
  """
  try:
    import numpy
  except:
    paraview.print_error("Error: Cannot import numpy")

  shape = numpy_array.shape
  if len(shape) < 2:
    raise Exception('numpy array must have dimensionality of at least 2')

  h, w = shape[0], shape[1]
  c = 1
  if len(shape) == 3:
    c = shape[2]

  # Reshape 2D image to 1D array suitable for conversion to a
  # vtkArray with numpy_support.numpy_to_vtk()
  linear_array = numpy.reshape(numpy_array, (w*h, c))

  try:
    from vtkmodules.util import numpy_support
  except:
    paraview.print_error("Error: Cannot import vtkmodules.util.numpy_support")

  vtk_array = numpy_support.numpy_to_vtk(linear_array)

  image = vtkImageData()
  image.SetDimensions(w, h, 1)
  image.AllocateScalars(vtk_array.GetDataType(), 4)
  image.GetPointData().GetScalars().DeepCopy(vtk_array)

  return image
コード例 #12
0
"""This is a test to test the paraview proxy manager API."""
from paraview import servermanager, print_info, print_error

import sys

servermanager.Connect()

for source in dir(servermanager.sources):
    try:
        print_info('Creating %s ...' % source)
        if source in [
                "GenericIOReader", 'EnsembleDataReader', 'openPMDReader'
        ]:
            print_info("...skipping (in exclusion list)")
        else:
            s = getattr(servermanager.sources, source)()
            s.UpdateVTKObjects()
            print_info("...... ok")
    except:
        print_error("failed!")
        raise RuntimeError('Failed to create %s' % source)
コード例 #13
0
    def UpdateCinema(self, view, datadescription, specLevel):
        """ called from catalyst at each timestep to add to the cinema database """
        if not view.IsA("vtkSMRenderViewProxy") == True:
            return

        try:
            import cinema_python.adaptors.explorers as explorers
            import cinema_python.adaptors.paraview.pv_explorers as pv_explorers
            import cinema_python.adaptors.paraview.pv_introspect as pv_introspect
        except ImportError as e:
            import paraview
            paraview.print_error("Cannot import cinema")
            paraview.print_error(e)
            return

        #figure out where to put this store
        import os.path
        vfname = view.cpFileName
        extension = os.path.splitext(vfname)[1]
        vfname = vfname[0:vfname.rfind("_")] #strip _num.ext
        fname = os.path.join(os.path.dirname(vfname),
                             "cinema",
                             os.path.basename(vfname),
                             "info.json")

        def float_limiter(x):
            #a shame, but needed to make sure python, javascript and (directory/file)name agree
            if isinstance(x, (float)):
                return '%.6e' % x #arbitrarily chose 6 significant digits
            else:
                return x

        #what time?
        timestep = datadescription.GetTimeStep()
        time = datadescription.GetTime()
        view.ViewTime = time
        formatted_time = float_limiter(time)

        # Include camera information in the user defined parameters.
        # pv_introspect uses __CinemaTracks to customize the exploration.
        co = view.cpCinemaOptions
        camType = co["camera"]
        if "phi" in co:
            self.__CinemaTracks["phi"] = co["phi"]
        if "theta" in co:
            self.__CinemaTracks["theta"] = co["theta"]
        if "roll" in co:
            self.__CinemaTracks["roll"] = co["roll"]

        tracking_def = {}
        if "tracking" in co:
            tracking_def = co['tracking']

        #figure out what we show now
        pxystate= pv_introspect.record_visibility()
        # a conservative global bounds for consistent z scaling
        minbds, maxbds  = pv_introspect.max_bounds()

        #make sure depth rasters are consistent
        view.MaxClipBounds = [minbds, maxbds, minbds, maxbds, minbds, maxbds]
        view.LockBounds = 1

        disableValues = False if 'noValues' not in co else co['noValues']

        if specLevel=="B":
            p = pv_introspect.inspect(skip_invisible=True)
        else:
            p = pv_introspect.inspect(skip_invisible=False)
        fs = pv_introspect.make_cinema_store(p, fname, view,
                                             forcetime = formatted_time,
                                             userDefined = self.__CinemaTracks,
                                             specLevel = specLevel,
                                             camType = camType,
                                             extension = extension,
                                             disableValues = disableValues)

        #all nodes participate, but only root can writes out the files
        pm = servermanager.vtkProcessModule.GetProcessModule()
        pid = pm.GetPartitionId()

        enableFloatVal = False if 'floatValues' not in co else co['floatValues']

        pv_introspect.explore(fs, p, iSave = (pid == 0),
                              currentTime = {'time':formatted_time},
                              userDefined = self.__CinemaTracks,
                              specLevel = specLevel,
                              camType = camType,
                              tracking = tracking_def,
                              floatValues = enableFloatVal,
                              disableValues = disableValues)
        if pid == 0:
            fs.save()

        view.LockBounds = 0

        #restore what we showed
        pv_introspect.restore_visibility(pxystate)
        return os.path.basename(vfname)
コード例 #14
0
import paraview

try:
    from vtkmodules.vtkCommonComputationalGeometry import *
except ImportError:
    #paraview.print_error("Error: Could not import vtkCommonComputationalGeometry")
    pass
from vtkmodules.vtkCommonCore import *
from vtkmodules.vtkCommonDataModel import *
from vtkmodules.vtkCommonExecutionModel import *
try:
    from vtkmodules.vtkCommonMath import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonMath")
try:
    from vtkmodules.vtkCommonMisc import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonMisc")
try:
    from vtkmodules.vtkCommonSystem import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonSystem")
try:
    from vtkmodules.vtkCommonTransforms import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonTransforms")
from vtkmodules.vtkFiltersProgrammable import *
from vtkmodules.vtkParallelCore import *
try:
    from vtkmodules.vtkRenderingCore import vtkCamera
except ImportError:
コード例 #15
0
ファイル: __init__.py プロジェクト: 151706061/ParaView
import paraview

try:
    from vtkCommonComputationalGeometry import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonComputationalGeometry")
from vtkCommonCore import *
from vtkCommonDataModel import *
from vtkCommonExecutionModel import *
try:
    from vtkCommonMath import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonMath")
try:
    from vtkCommonMisc import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonMisc")
try:
    from vtkCommonSystem import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonSystem")
try:
    from vtkCommonTransforms import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonTransforms")
from vtkFiltersProgrammable import *
from vtkParallelCore import *
try:
    from vtkRenderingCore import vtkCamera
except ImportError:
    paraview.print_error("Error: Could not import vtkRenderingCore")
コード例 #16
0
        for name in names:
           if (name.find(filename) > -1) and ( (name.find('.dll') > -1) or (name.find('.so') > -1) or (name.find('.dylib') > -1)):
              return os.path.join(root, name)
    raise RuntimeError ('File not found')
#--------------------

print_info ("Start multi-server testing")

options = servermanager.vtkRemotingCoreConfiguration.GetInstance()
available_server_urls = options.GetServerURL().split('|')
built_in_connection = servermanager.ActiveConnection

# Test if the built-in connection is here
if (len(servermanager.Connections) != 1):
  errors += 1
  print_error("Error pvpython should be connected to a built-in session. Currently connected to ", servermanager.Connections)

url = available_server_urls[0]
print_info ("Connect to first server %s", url)
server1_connection = Connect(getHost(url), getPort(url))

# Test that we have one more connection
if (len(servermanager.Connections) != 2):
  errors += 1
  print_error("Error pvpython should be connected to a built-in session + one remote one. Currently connected to ", servermanager.Connections)

url = available_server_urls[1]
print_info ("Connect to second server %s", url)
server2_connection = Connect(getHost(url), getPort(url))

# Test that we have one more connection
コード例 #17
0
ファイル: python_view.py プロジェクト: 151706061/ParaView
#     This software is distributed WITHOUT ANY WARRANTY without even
#     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#     PURPOSE.  See the above copyright notice for more information.
#
#==============================================================================
import paraview
import vtk

from vtk.vtkPVServerImplementationCore import *
from vtk.vtkPVClientServerCoreCore import *
from vtk.vtkPVServerManagerCore import *

try:
  from vtk.vtkPVServerManagerDefault import *
except:
  paraview.print_error("Error: Cannot import vtkPVServerManagerDefault")
try:
  from vtk.vtkPVServerManagerRendering import *
except:
  paraview.print_error("Error: Cannot import vtkPVServerManagerRendering")
try:
  from vtk.vtkPVServerManagerApplication import *
except:
  paraview.print_error("Error: Cannot import vtkPVServerManagerApplication")
from vtk.vtkPVCommon import *


def numpy_to_image(numpy_array):
  """
  @brief Convert a numpy 2D or 3D array to a vtkImageData object
  @param numpy_array 2D or 3D numpy array containing image data
コード例 #18
0
ファイル: pv-vtk-all.py プロジェクト: sakjain92/paraview
import paraview

try:
    from vtkmodules.vtkCommonComputationalGeometry import *
except ImportError:
    paraview.print_error(
        "Error: Could not import vtkCommonComputationalGeometry")
from vtkmodules.vtkCommonCore import *
from vtkmodules.vtkCommonDataModel import *
from vtkmodules.vtkCommonExecutionModel import *
try:
    from vtkmodules.vtkCommonMath import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonMath")
try:
    from vtkmodules.vtkCommonMisc import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonMisc")
try:
    from vtkmodules.vtkCommonSystem import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonSystem")
try:
    from vtkmodules.vtkCommonTransforms import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonTransforms")
from vtkmodules.vtkFiltersProgrammable import *
from vtkmodules.vtkParallelCore import *
try:
    from vtkmodules.vtkRenderingCore import vtkCamera
except ImportError:
コード例 #19
0
LoadDistributedPlugin('SurfaceLIC', ns=globals())

filename = smtesting.DataDir + '/Testing/Data/disk_out_ref.ex2'
data = OpenDataFile(filename)
UpdatePipeline()
view = CreateRenderView()
rep = Show(view=view, representationType="UnstructuredGridRepresentation")

# Ensure that loading the SurfaceLIC lead to adding the SelectLICVectors
# property correctly.
print_info(rep.GetProperty("SelectInputVectors"))
print_info(rep.SelectInputVectors)

try:
    LoadDistributedPlugin("NonExistantPluginName", ns=globals())
    print_error(
        "Error: LoadDistributedPlugin should have thrown a RunTimeError!!!")
    sys.exit(1)
except:
    # We expect an error.
    pass

try:
    MomentVectors()
    print_error(
        "Error: MomentVectors should not exist before loading the plugin")
    sys.exit(1)
except:
    pass

LoadDistributedPlugin('Moments', ns=globals())
MomentVectors()
コード例 #20
0
ファイル: __init__.py プロジェクト: EricAlex/ThirdParty-dev
import paraview

try:
    from vtkCommonComputationalGeometryPython import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonComputationalGeometryPython")
from vtkCommonCorePython import *
from vtkCommonDataModelPython import *
from vtkCommonExecutionModelPython import *
try:
    from vtkCommonMathPython import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonMathPython")
try:
    from vtkCommonMiscPython import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonMiscPython")
try:
    from vtkCommonSystemPython import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonSystemPython")
try:
    from vtkCommonTransformsPython import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonTransformsPython")
from vtkFiltersProgrammablePython import *
from vtkParallelCorePython import *
try:
    from vtkRenderingCorePython import vtkCamera
except ImportError:
    paraview.print_error("Error: Could not import vtkRenderingCorePython")
コード例 #21
0
#     This software is distributed WITHOUT ANY WARRANTY without even
#     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#     PURPOSE.  See the above copyright notice for more information.
#
#==============================================================================
import paraview
import vtk

from vtkPVServerImplementationCorePython import *
from vtkPVClientServerCoreCorePython import *
from vtkPVServerManagerCorePython import *

try:
    from vtkPVServerManagerDefaultPython import *
except:
    paraview.print_error(
        "Error: Cannot import vtkPVServerManagerDefaultPython")
try:
    from vtkPVServerManagerRenderingPython import *
except:
    paraview.print_error(
        "Error: Cannot import vtkPVServerManagerRenderingPython")
try:
    from vtkPVServerManagerApplicationPython import *
except:
    paraview.print_error(
        "Error: Cannot import vtkPVServerManagerApplicationPython")
from vtkPVCommonPython import *


def numpy_to_image(numpy_array):
    """
コード例 #22
0
import paraview

try:
    from vtkCommonComputationalGeometryPython import *
except ImportError:
    paraview.print_error(
        "Error: Could not import vtkCommonComputationalGeometryPython")
from vtkCommonCorePython import *
from vtkCommonDataModelPython import *
from vtkCommonExecutionModelPython import *
try:
    from vtkCommonMathPython import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonMathPython")
try:
    from vtkCommonMiscPython import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonMiscPython")
try:
    from vtkCommonSystemPython import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonSystemPython")
try:
    from vtkCommonTransformsPython import *
except ImportError:
    paraview.print_error("Error: Could not import vtkCommonTransformsPython")
from vtkFiltersProgrammablePython import *
from vtkParallelCorePython import *
try:
    from vtkRenderingCorePython import vtkCamera
except ImportError:
コード例 #23
0
    def UpdateCinema(self, view, datadescription, specLevel):
        """ called from catalyst at each timestep to add to the cinema database """
        if not view.IsA("vtkSMRenderViewProxy") == True:
            return

        try:
            import paraview.tpl.cinema_python.adaptors.explorers as explorers
            import paraview.tpl.cinema_python.adaptors.paraview.pv_explorers as pv_explorers
            import paraview.tpl.cinema_python.adaptors.paraview.pv_introspect as pv_introspect
        except ImportError as e:
            import paraview
            paraview.print_error("Cannot import cinema")
            paraview.print_error(e)
            return

        #figure out where to put this store
        import os.path
        vfname = view.cpFileName
        extension = os.path.splitext(vfname)[1]
        vfname = vfname[0:vfname.rfind("_")]  #strip _num.ext
        fname = os.path.join(os.path.dirname(vfname), "cinema",
                             os.path.basename(vfname), "info.json")

        def float_limiter(x):
            #a shame, but needed to make sure python, javascript and (directory/file)name agree
            if isinstance(x, (float)):
                return '%.6e' % x  #arbitrarily chose 6 significant digits
            else:
                return x

        #what time?
        time = datadescription.GetTime()
        view.ViewTime = time
        formatted_time = float_limiter(time)

        #ensure that cinema operates on the specified view
        simple.SetActiveView(view)

        # Include camera information in the user defined parameters.
        # pv_introspect uses __CinemaTracks to customize the exploration.
        co = view.cpCinemaOptions
        camType = co["camera"]
        if "phi" in co:
            self.__CinemaTracks["phi"] = co["phi"]
        if "theta" in co:
            self.__CinemaTracks["theta"] = co["theta"]
        if "roll" in co:
            self.__CinemaTracks["roll"] = co["roll"]

        tracking_def = {}
        if "tracking" in co:
            tracking_def = co['tracking']

        #figure out what we show now
        pxystate = pv_introspect.record_visibility()
        # a conservative global bounds for consistent z scaling
        minbds, maxbds = pv_introspect.max_bounds()

        #make sure depth rasters are consistent
        view.MaxClipBounds = [minbds, maxbds, minbds, maxbds, minbds, maxbds]
        view.LockBounds = 1

        disableValues = False if 'noValues' not in co else co['noValues']

        if specLevel == "B":
            p = pv_introspect.inspect(skip_invisible=True)
        else:
            p = pv_introspect.inspect(skip_invisible=False)
        fs = pv_introspect.make_cinema_store(p,
                                             fname,
                                             view,
                                             forcetime=formatted_time,
                                             userDefined=self.__CinemaTracks,
                                             specLevel=specLevel,
                                             camType=camType,
                                             extension=extension,
                                             disableValues=disableValues)

        #all nodes participate, but only root can writes out the files
        pm = servermanager.vtkProcessModule.GetProcessModule()
        pid = pm.GetPartitionId()

        enableFloatVal = False if 'floatValues' not in co else co['floatValues']

        new_files = {}
        ret = pv_introspect.explore(fs,
                                    p,
                                    iSave=(pid == 0),
                                    currentTime={'time': formatted_time},
                                    userDefined=self.__CinemaTracks,
                                    specLevel=specLevel,
                                    camType=camType,
                                    tracking=tracking_def,
                                    floatValues=enableFloatVal,
                                    disableValues=disableValues)
        if pid == 0:
            fs.save()
        new_files[vfname] = ret

        view.LockBounds = 0

        #restore what we showed
        pv_introspect.restore_visibility(pxystate)
        return os.path.basename(vfname), new_files
コード例 #24
0
import paraview
import vtkParallelCorePython
import vtk
from mpi4py import MPI
import os, sys

paraview.options.batch = True
paraview.options.symmetric = True
from vtkPVClientServerCoreCorePython import *
try:
    from vtkPVServerManagerApplicationPython import *
except:
    paraview.print_error("Error: Cannot import vtkPVServerManagerApplicationPython")

if not vtkProcessModule.GetProcessModule():
    pvoptions = None
    if paraview.options.batch:
        pvoptions = vtkPVOptions();
        pvoptions.SetProcessType(vtkPVOptions.PVBATCH)
        if paraview.options.symmetric:
            pvoptions.SetSymmetricMPIMode(True)
    vtkInitializationHelper.Initialize(sys.executable, vtkProcessModule.PROCESS_BATCH, pvoptions)

import paraview.servermanager as pvsm
# we need ParaView 4.2 since ParaView 4.1 doesn't properly wrap
# vtkPVPythonCatalystPython
if pvsm.vtkSMProxyManager.GetVersionMajor() != 4 or \
        pvsm.vtkSMProxyManager.GetVersionMinor() !=2:
    print 'Must use ParaView v4.2'
    sys.exit(0)