Exemple #1
0
 def SetCells(self, cellTypes, cellLocations, cells):
     """Given cellTypes, cellLocations, cells as VTKArrays,
     populates the unstructured grid data structures."""
     from vtk import VTK_ID_TYPE
     from vtk.vtkCommonDataModel import vtkCellArray
     cellTypes = numpyTovtkDataArray(cellTypes)
     cellLocations = numpyTovtkDataArray(cellLocations, array_type=VTK_ID_TYPE)
     cells = numpyTovtkDataArray(cells, array_type=VTK_ID_TYPE)
     ca = vtkCellArray()
     ca.SetCells(cellTypes.GetNumberOfTuples(), cells)
     self.VTKObject.SetCells(cellTypes, cellLocations, ca)
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)