Esempio n. 1
0
 def setUp(self):
     self.cell = vtkStructuredGrid()
     pts = vtkPoints()
     pts.SetDataTypeToDouble()
     pts.InsertNextPoint(-1.0, -1.0, -1.0)
     pts.InsertNextPoint( 1.0, -1.0, -1.0)
     pts.InsertNextPoint( 1.0,  1.0, -1.0)
     pts.InsertNextPoint(-1.0,  1.0, -1.0)
     pts.InsertNextPoint(-1.0, -1.0,  1.0)
     pts.InsertNextPoint( 1.0, -1.0,  1.0)
     pts.InsertNextPoint( 1.0,  1.0,  1.0)
     pts.InsertNextPoint(-1.0,  1.0,  1.0)
     self.cell.SetDimensions(2,2,2)
     self.cell.SetPoints(pts)
     scalar = vtkDoubleArray()
     scalar.SetName('scalar')
     scalar.SetNumberOfTuples(8)
     scalar.SetValue(0, 0.0)
     scalar.SetValue(1, 0.0)
     scalar.SetValue(2, 0.0)
     scalar.SetValue(3, 0.0)
     scalar.SetValue(4, 1.0)
     scalar.SetValue(5, 1.0)
     scalar.SetValue(6, 1.0)
     scalar.SetValue(7, 1.0)
     self.cell.GetPointData().SetScalars(scalar)
Esempio n. 2
0
 def setUp(self):
     self.cell = vtkUnstructuredGrid()
     pts = vtkPoints()
     pts.SetDataTypeToDouble()
     pts.InsertNextPoint(-1.0, -1.0, -1.0)
     pts.InsertNextPoint( 1.0, -1.0, -1.0)
     pts.InsertNextPoint( 1.0,  1.0, -1.0)
     pts.InsertNextPoint(-1.0,  1.0, -1.0)
     pts.InsertNextPoint(-1.0, -1.0,  1.0)
     pts.InsertNextPoint( 1.0, -1.0,  1.0)
     pts.InsertNextPoint( 1.0,  1.0,  1.0)
     pts.InsertNextPoint(-1.0,  1.0,  1.0)
     self.cell.SetPoints(pts)
     self.cell.Allocate(1,1)
     ids = vtkIdList()
     for i in range(8):
         ids.InsertId(i,i)
     self.cell.InsertNextCell(vtk_const.VTK_HEXAHEDRON, ids)
     scalar = vtkDoubleArray()
     scalar.SetName('scalar')
     scalar.SetNumberOfTuples(8)
     scalar.SetValue(0, 0.0)
     scalar.SetValue(1, 0.0)
     scalar.SetValue(2, 0.0)
     scalar.SetValue(3, 0.0)
     scalar.SetValue(4, 1.0)
     scalar.SetValue(5, 1.0)
     scalar.SetValue(6, 1.0)
     scalar.SetValue(7, 1.0)
     self.cell.GetPointData().SetScalars(scalar)
Esempio n. 3
0
 def SetPoints(self, pts):
     """Given a VTKArray instance, sets the points of the dataset."""
     from vtk.vtkCommonCore import vtkPoints
     pts = numpyTovtkDataArray(pts)
     p = vtkPoints()
     p.SetData(pts)
     self.VTKObject.SetPoints(p)
Esempio n. 4
0
 def SetPoints(self, pts):
     """Given a VTKArray instance, sets the points of the dataset."""
     from vtk.vtkCommonCore import vtkPoints
     pts = numpyTovtkDataArray(pts)
     p = vtkPoints()
     p.SetData(pts)
     self.VTKObject.SetPoints(p)
def processPartition(idx, iterator):
    import os
    os.environ["PMI_PORT"] = pmi_port
    os.environ["PMI_ID"] = str(idx)
    os.environ["PV_ALLOW_BATCH_INTERACTION"] = "1"
    os.environ["DISPLAY"] = ":0"

    import paraview
    paraview.options.batch = True

    from vtk.vtkPVVTKExtensionsCore import vtkDistributedTrivialProducer
    from vtk.vtkCommonCore import vtkIntArray, vtkPoints
    from vtk.vtkCommonDataModel import vtkPolyData, vtkPointData, vtkCellArray

    pointData = vtkIntArray()
    pointData.SetName('scalar')
    pointData.Allocate(maxIndex)

    partData = vtkIntArray()
    partData.SetName('pid')
    partData.Allocate(maxIndex)

    points = vtkPoints()
    points.Allocate(maxIndex)

    for row in iterator:
        coord = idxToCoord(row[0])
        points.InsertNextPoint(coord[0], coord[1], coord[2])
        pointData.InsertNextTuple1(row[1])
        partData.InsertNextTuple1(idx)

    cells = vtkCellArray()
    cells.Allocate(points.GetNumberOfPoints() + 1)
    cells.InsertNextCell(points.GetNumberOfPoints())
    for i in range(points.GetNumberOfPoints()):
        cells.InsertCellPoint(i)

    dataset = vtkPolyData()
    dataset.SetPoints(points)
    dataset.SetVerts(cells)
    dataset.GetPointData().AddArray(pointData)
    dataset.GetPointData().SetScalars(partData)

    vtkDistributedTrivialProducer.SetGlobalOutput('Spark', dataset)

    from vtk.vtkPVClientServerCoreCore import vtkProcessModule
    from paraview import simple
    from paraview.web import wamp as pv_wamp
    from paraview.web import protocols as pv_protocols
    from vtk.web import server

    pm = vtkProcessModule.GetProcessModule()

    class Options(object):
        debug = False
        nosignalhandlers = True
        host = 'localhost'
        port = 9753
        timeout = 300
        content = '/data/sebastien/SparkMPI/runtime/visualizer/dist'
        forceFlush = False
        sslKey = ''
        sslCert = ''
        ws = 'ws'
        lp = 'lp'
        hp = 'hp'
        nows = False
        nobws = False
        nolp = False
        fsEndpoints = ''
        uploadPath = None
        testScriptPath = ''
        baselineImgDir = ''
        useBrowser = 'nobrowser'
        tmpDirectory = '.'
        testImgFile = ''

    class _VisualizerServer(pv_wamp.PVServerProtocol):
        dataDir = '/data'
        groupRegex = "[0-9]+\\.[0-9]+\\.|[0-9]+\\."
        excludeRegex = "^\\.|~$|^\\$"
        allReaders = True
        viewportScale = 1.0
        viewportMaxWidth = 2560
        viewportMaxHeight = 1440

        def initialize(self):
            # Bring used components
            self.registerVtkWebProtocol(
                pv_protocols.ParaViewWebFileListing(
                    _VisualizerServer.dataDir, "Home",
                    _VisualizerServer.excludeRegex,
                    _VisualizerServer.groupRegex))
            self.registerVtkWebProtocol(
                pv_protocols.ParaViewWebProxyManager(
                    baseDir=_VisualizerServer.dataDir,
                    allowUnconfiguredReaders=_VisualizerServer.allReaders))
            self.registerVtkWebProtocol(pv_protocols.ParaViewWebColorManager())
            self.registerVtkWebProtocol(pv_protocols.ParaViewWebMouseHandler())
            self.registerVtkWebProtocol(
                pv_protocols.ParaViewWebViewPort(
                    _VisualizerServer.viewportScale,
                    _VisualizerServer.viewportMaxWidth,
                    _VisualizerServer.viewportMaxHeight))
            self.registerVtkWebProtocol(
                pv_protocols.ParaViewWebViewPortImageDelivery())
            self.registerVtkWebProtocol(
                pv_protocols.ParaViewWebViewPortGeometryDelivery())
            self.registerVtkWebProtocol(pv_protocols.ParaViewWebTimeHandler())
            self.registerVtkWebProtocol(
                pv_protocols.ParaViewWebSelectionHandler())
            self.registerVtkWebProtocol(
                pv_protocols.ParaViewWebWidgetManager())
            self.registerVtkWebProtocol(
                pv_protocols.ParaViewWebKeyValuePairStore())
            self.registerVtkWebProtocol(
                pv_protocols.ParaViewWebSaveData(
                    baseSavePath=_VisualizerServer.dataDir))
            # Disable interactor-based render calls
            simple.GetRenderView().EnableRenderOnInteraction = 0
            simple.GetRenderView().Background = [0, 0, 0]
            # Update interaction mode
            pxm = simple.servermanager.ProxyManager()
            interactionProxy = pxm.GetProxy('settings',
                                            'RenderViewInteractionSettings')
            interactionProxy.Camera3DManipulators = [
                'Rotate', 'Pan', 'Zoom', 'Pan', 'Roll', 'Pan', 'Zoom',
                'Rotate', 'Zoom'
            ]

    args = Options()
    if pm.GetPartitionId() == 0:
        producer = simple.DistributedTrivialProducer()
        producer.UpdateDataset = ''
        producer.UpdateDataset = 'Spark'
        server.start_webserver(options=args, protocol=_VisualizerServer)
        pm.GetGlobalController().TriggerBreakRMIs()

    yield (idx, targetPartition)
Esempio n. 6
0
def unstructured_from_composite_arrays(points, arrays, controller=None):
    """Given a set of VTKCompositeDataArrays, creates a vtkUnstructuredGrid.
    The main goal of this function is to transform the output of XXX_per_block()
    methods to a single dataset that can be visualized and further processed.
    Here arrays is an iterable (e.g. list) of (array, name) pairs. Here is
    an example:

    centroid = mean_per_block(composite_data.Points)
    T = mean_per_block(composite_data.PointData['Temperature'])
    ug = unstructured_from_composite_arrays(centroid, (T, 'Temperature'))

    When called in parallel, this function makes sure that each array in
    the input dataset is represented only on 1 process. This is important
    because methods like mean_per_block() return the same value for blocks
    that are partitioned on all of the participating processes. If the
    same point were to be created across multiple processes in the output,
    filters like histogram would report duplicate values erroneously.
    """

    try:
        dataset = points.DataSet
    except AttributeError:
        dataset = None

    if dataset is None and points is not dsa.NoneArray:
        raise ValueError(
            "Expecting a points arrays with an associated dataset.")

    if points is dsa.NoneArray:
        cpts = []
    else:
        cpts = points.Arrays
    ownership = numpy.zeros(len(cpts), dtype=numpy.int32)
    rank = 0

    # Let's first create a map of array index to composite ids.
    if dataset is None:
        ids = []
    else:
        it = dataset.NewIterator()
        it.UnRegister(None)
        itr = cpts.__iter__()
        ids = numpy.empty(len(cpts), dtype=numpy.int32)
        counter = 0
        while not it.IsDoneWithTraversal():
            _id = it.GetCurrentFlatIndex()
            ids[counter] = _id
            counter += 1
            it.GoToNextItem()

    if controller is None and vtkMultiProcessController is not None:
        controller = vtkMultiProcessController.GetGlobalController()
    if controller and controller.IsA("vtkMPIController"):
        from mpi4py import MPI
        comm = vtkMPI4PyCommunicator.ConvertToPython(
            controller.GetCommunicator())
        rank = comm.Get_rank()

        # Determine the max id to use for reduction
        # operations

        # Get all ids from dataset, including empty ones.
        lmax_id = numpy.int32(0)
        if dataset is not None:
            it = dataset.NewIterator()
            it.UnRegister(None)
            it.SetSkipEmptyNodes(False)
            while not it.IsDoneWithTraversal():
                _id = it.GetCurrentFlatIndex()
                lmax_id = numpy.max((lmax_id, _id)).astype(numpy.int32)
                it.GoToNextItem()
        max_id = numpy.array(0, dtype=numpy.int32)
        mpitype = _lookup_mpi_type(numpy.int32)
        comm.Allreduce([lmax_id, mpitype], [max_id, mpitype], MPI.MAX)

        # Now we figure out which processes have which ids
        lownership = numpy.empty(max_id, dtype=numpy.int32)
        lownership.fill(numpy.iinfo(numpy.int32).max)

        ownership = numpy.empty(max_id, dtype=numpy.int32)

        if dataset is not None:
            it = dataset.NewIterator()
            it.UnRegister(None)
            it.InitTraversal()
            itr = cpts.__iter__()
            while not it.IsDoneWithTraversal():
                _id = it.GetCurrentFlatIndex()
                if itr.next() is not dsa.NoneArray:
                    lownership[_id] = rank
                it.GoToNextItem()
        mpitype = _lookup_mpi_type(numpy.int32)
        # The process with the lowest id containing a block will
        # produce the output for that block.
        comm.Allreduce([lownership, mpitype], [ownership, mpitype], MPI.MIN)

    # Iterate over blocks to produce points and arrays
    from vtk.vtkCommonDataModel import vtkUnstructuredGrid
    from vtk.vtkCommonCore import vtkDoubleArray, vtkPoints
    ugrid = vtkUnstructuredGrid()
    da = vtkDoubleArray()
    da.SetNumberOfComponents(3)
    pts = vtkPoints()
    pts.SetData(da)
    counter = 0
    for pt in cpts:
        if ownership[ids[counter]] == rank:
            pts.InsertNextPoint(tuple(pt))
        counter += 1
    ugrid.SetPoints(pts)

    for ca, name in arrays:
        if ca is not dsa.NoneArray:
            da = vtkDoubleArray()
            ncomps = ca.Arrays[0].flatten().shape[0]
            da.SetNumberOfComponents(ncomps)
            counter = 0
            for a in ca.Arrays:
                if ownership[ids[counter]] == rank:
                    a = a.flatten()
                    for i in range(ncomps):
                        da.InsertNextValue(a[i])
                counter += 1
            if len(a) > 0:
                da.SetName(name)
                ugrid.GetPointData().AddArray(da)
    return ugrid
Esempio n. 7
0
def unstructured_from_composite_arrays(points, arrays, controller=None):
    """Given a set of VTKCompositeDataArrays, creates a vtkUnstructuredGrid.
    The main goal of this function is to transform the output of XXX_per_block()
    methods to a single dataset that can be visualized and further processed.
    Here arrays is an iterable (e.g. list) of (array, name) pairs. Here is
    an example:

    centroid = mean_per_block(composite_data.Points)
    T = mean_per_block(composite_data.PointData['Temperature'])
    ug = unstructured_from_composite_arrays(centroid, (T, 'Temperature'))

    When called in parallel, this function makes sure that each array in
    the input dataset is represented only on 1 process. This is important
    because methods like mean_per_block() return the same value for blocks
    that are partitioned on all of the participating processes. If the
    same point were to be created across multiple processes in the output,
    filters like histogram would report duplicate values erroneously.
    """

    try:
        dataset = points.DataSet
    except AttributeError:
        dataset = None

    if dataset is None and points is not dsa.NoneArray:
        raise ValueError, "Expecting a points arrays with an associated dataset."

    if points is dsa.NoneArray:
        cpts = []
    else:
        cpts = points.Arrays
    ownership = numpy.zeros(len(cpts), dtype=numpy.int32)
    rank = 0

    # Let's first create a map of array index to composite ids.
    if dataset is None:
        ids = []
    else:
        it = dataset.NewIterator()
        it.UnRegister(None)
        itr = cpts.__iter__()
        ids = numpy.empty(len(cpts), dtype=numpy.int32)
        counter = 0
        while not it.IsDoneWithTraversal():
            _id = it.GetCurrentFlatIndex()
            ids[counter] = _id
            counter += 1
            it.GoToNextItem()

    if controller is None and vtkMultiProcessController is not None:
        controller = vtkMultiProcessController.GetGlobalController()
    if controller and controller.IsA("vtkMPIController"):
        from mpi4py import MPI
        comm = vtkMPI4PyCommunicator.ConvertToPython(controller.GetCommunicator())
        rank = comm.Get_rank()

        # Determine the max id to use for reduction
        # operations

        # Get all ids from dataset, including empty ones.
        lmax_id = numpy.int32(0)
        if dataset is not None:
            it = dataset.NewIterator()
            it.UnRegister(None)
            it.SetSkipEmptyNodes(False)
            while not it.IsDoneWithTraversal():
                _id = it.GetCurrentFlatIndex()
                lmax_id = numpy.max((lmax_id, _id)).astype(numpy.int32)
                it.GoToNextItem()
        max_id = numpy.array(0, dtype=numpy.int32)
        mpitype = _lookup_mpi_type(numpy.int32)
        comm.Allreduce([lmax_id, mpitype], [max_id, mpitype], MPI.MAX)

        # Now we figure out which processes have which ids
        lownership = numpy.empty(max_id, dtype = numpy.int32)
        lownership.fill(numpy.iinfo(numpy.int32).max)

        ownership = numpy.empty(max_id, dtype = numpy.int32)

        if dataset is not None:
            it = dataset.NewIterator()
            it.UnRegister(None)
            it.InitTraversal()
            itr = cpts.__iter__()
            while not it.IsDoneWithTraversal():
                _id = it.GetCurrentFlatIndex()
                if itr.next() is not dsa.NoneArray:
                    lownership[_id] = rank
                it.GoToNextItem()
        mpitype = _lookup_mpi_type(numpy.int32)
        # The process with the lowest id containing a block will
        # produce the output for that block.
        comm.Allreduce([lownership, mpitype], [ownership, mpitype], MPI.MIN)

    # Iterate over blocks to produce points and arrays
    from vtk.vtkCommonDataModel import vtkUnstructuredGrid
    from vtk.vtkCommonCore import vtkDoubleArray, vtkPoints
    ugrid = vtkUnstructuredGrid()
    da = vtkDoubleArray()
    da.SetNumberOfComponents(3)
    pts = vtkPoints()
    pts.SetData(da)
    counter = 0
    for pt in cpts:
        if ownership[ids[counter]] == rank:
            pts.InsertNextPoint(tuple(pt))
        counter += 1
    ugrid.SetPoints(pts)

    for ca, name in arrays:
        if ca is not dsa.NoneArray:
            da = vtkDoubleArray()
            ncomps = ca.Arrays[0].flatten().shape[0]
            da.SetNumberOfComponents(ncomps)
            counter = 0
            for a in ca.Arrays:
                if ownership[ids[counter]] == rank:
                    a = a.flatten()
                    for i in range(ncomps):
                        da.InsertNextValue(a[i])
                counter += 1
            if len(a) > 0:
                da.SetName(name)
                ugrid.GetPointData().AddArray(da)
    return ugrid