Exemplo n.º 1
0
    def __init__(self):
        from pyvista import examples
        topo = examples.load_random_hills()

        from paraview import simple

        tp = simple.TrivialProducer()
        tp.GetClientSideObject().SetOutput(topo)

        simple.Show(tp)
Exemplo n.º 2
0
    def loadDemoData(self):
        # Read in sample file
        reader = vtk.vtkImageReader2Factory.CreateImageReader2(DEMO_FILE)
        reader.SetFileName(DEMO_FILE)
        reader.Update()
        imageData = reader.GetOutput()

        # Display image
        proxy = pv.TrivialProducer()
        tp = proxy.GetClientSideObject()
        tp.SetOutput(imageData)
        proxy.UpdateVTKObjects()

        pv.Show(proxy)
        pv.Render()
pointData = polyData.GetPointData()

# Set up a data array containing the point ordinal values
ordinalArrayName = "Ordinal"
ordinalRange = [0, NUM_POINTS - 1]
ordinalArray = vtkDoubleArray()
ordinalArray.SetName(ordinalArrayName)
ordinalArray.SetNumberOfComponents(1)
ordinalArray.SetNumberOfTuples(NUM_POINTS)

for i in xrange(NUM_POINTS):
    ordinalArray.SetTuple1(i, i)

pointData.AddArray(ordinalArray)

source = simple.TrivialProducer()
source.GetClientSideObject().SetOutput(polyData)

# create a calculator to compute distance
calculator1 = simple.Calculator(Input=source)
calculator1.ResultArrayName = 'Distance'
calculator1.Function = 'mag(coords)'

# create another calculator to compute inverse distance
calculator2 = simple.Calculator(Input=calculator1)
calculator2.ResultArrayName = 'Inverse Distance'
calculator2.Function = '%s-Distance' % str(NUM_POINTS - 1)

# Get the representation
rep = simple.Show(calculator2)
Exemplo n.º 4
0
    def updateScatterPlot(self, config):
        updateAxes = False
        updateColormap = False
        sprites = config['usePointSprites']
        showMesh = config['showMesh']

        if not self.dataTable:
            # initialize everything
            self.dataTable = self.divvyProtocol.getDataWithSelection()
            if self.divvyProtocol.getMesh():
                self.dataMesh = simple.TrivialProducer()
                self.dataMesh.GetClientSideObject().SetOutput(
                    self.divvyProtocol.getMesh())

            # copy data from the main protocol, and set up pipelilne
            self.trivProducer = simple.TrivialProducer()
            self.trivProducer.GetClientSideObject().SetOutput(self.dataTable)

            self.tableToPoints = simple.TableToPoints(Input=self.trivProducer)
            self.tableToPoints.XColumn = config['x']
            self.tableToPoints.YColumn = config['y']
            self.tableToPoints.ZColumn = config['z']
            self.tableToPoints.KeepAllDataArrays = 1

            self.tableToPoints.UpdatePipeline()

            self.outlineFilter = simple.Outline(Input=self.tableToPoints)
            self.outlineRepresentation = simple.GetRepresentation(
                self.outlineFilter, self.renderView)
            self.outlineRepresentation.DiffuseColor = [0.0, 0.0, 0.0]
            self.outlineRepresentation.Visibility = 0

            self.representation = simple.GetRepresentation(
                self.tableToPoints, self.renderView)
            self.representation.Representation = 'Surface'
            self.representation.PointSize = 5
            self.representation.Opacity = 1.0
            self.representation.InterpolateScalarsBeforeMapping = 0

            self.representation.Visibility = 1

            self.renderView.AxesGrid = 'GridAxes3DActor'
            self.renderView.AxesGrid.Visibility = 1
            self.renderView.AxesGrid.XTitleColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.YTitleColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.ZTitleColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.GridColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.ShowGrid = 1
            self.renderView.AxesGrid.XLabelColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.YLabelColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.ZLabelColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.DataScale = [1, 1, 1]

            self.renderView.OrientationAxesVisibility = 0
            self.renderView.Background = [1.0, 1.0, 1.0]
            self.renderView.BackgroundColorMode = 0  # PV 5.10
            self.renderView.UseColorPaletteForBackground = 0

            # create a LUT, if needed
            if 'colorBy' in config:
                vtkSMPVRepresentationProxy.SetScalarColoring(
                    self.representation.SMProxy, config['colorBy'], 0)
                vtkSMPVRepresentationProxy.RescaleTransferFunctionToDataRange(
                    self.representation.SMProxy, config['colorBy'], 0, False,
                    True)

            updateAxes = True
            updateColormap = True

        else:
            # update
            if self.arrays['x'] != config['x'] or \
              self.arrays['y'] != config['y'] or \
              self.arrays['z'] != config['z']:

                self.tableToPoints.XColumn = config['x']
                self.tableToPoints.YColumn = config['y']
                self.tableToPoints.ZColumn = config['z']

                self.dataTable.Modified()
                updateAxes = True

            if 'colorBy' in config and ( config['colorBy'] == USER_SELECTION or \
                 config['colorBy'] != \
                 vtkSMPVRepresentationProxy.GetArrayInformationForColorArray(self.representation.SMProxy).GetName()
                 or config['colorMapName'] != self._colorMapName) :
                updateColormap = True

        if updateAxes:
            self.arrays['x'] = config['x']
            self.arrays['y'] = config['y']
            self.arrays['z'] = config['z']
            self.renderView.AxesGrid.XTitle = config['x']
            self.renderView.AxesGrid.YTitle = config['y']
            self.renderView.AxesGrid.ZTitle = config['z']
            self.updateAxis(showMesh and self.dataMesh)

        if updateColormap:
            vtkSMPVRepresentationProxy.SetScalarColoring(
                self.representation.SMProxy, config['colorBy'], 0)
            if config['colorBy'] == USER_SELECTION:
                # Coloring by the user selection needs special handling
                if not self._selectionLutInitialized:
                    self.updateUserSelectionLutProperties()
            else:
                vtkSMPVRepresentationProxy.RescaleTransferFunctionToDataRange(
                    self.representation.SMProxy, config['colorBy'], 0, False,
                    True)
                self.colorManager.selectColorMap(
                    self.representation.GetGlobalIDAsString(),
                    config['colorMapName'])

        sizeRange = [1.0, 3.0]
        constPointSize = 3.0
        pointSize = 2.0
        try:
            sizeRange = [
                float(config['pointSizeMin']),
                float(config['pointSizeMax'])
            ]
            constPointSize = float(config['constantPointSize'])
            pointSize = float(config['pointSize'])
        except:
            print('Failed conversion', config['pointSizeMin'],
                  config['pointSizeMax'], config['constantPointSize'],
                  config['pointSize'])
            pass

        # Sprites are the ParaView Point Gaussian representation, and allow shader-based point drawing.
        if sprites:
            self.representation.Visibility = 0
            self.representation.Representation = 'Point Gaussian'
            # Needed for ParaView 5.4 - not sure if it'll mess up older ones.
            self.representation.ShaderPreset = 'Custom'

            reprInfo = self.representationMap['Black-edged circle']

            if config['pointRepresentation'] and config[
                    'pointRepresentation'] is not '':
                reprInfo = self.representationMap[
                    config['pointRepresentation']]

            self.representation.GaussianRadius = reprInfo['radius']
            self.representation.CustomShader = reprInfo['shader']

            # vary point size with array, maybe.
            if config['pointSizeBy'] and config['pointSizeBy'] != '':
                # sizeRange = [float(config['pointSizeMin']), float(config['pointSizeMax']) ]
                dataRange = self.dataTable.GetColumnByName(
                    config['pointSizeBy']).GetRange()
                scaleFunction = str(config['pointSizeFunction'])
                if config['pointSizeBy'] == USER_SELECTION:
                    if sizeRange[0] != self.userSelPointSizeRange[
                            0] or sizeRange[1] != self.userSelPointSizeRange[1]:
                        self.userSelPointSizeRange[0] = sizeRange[0]
                        self.userSelPointSizeRange[1] = sizeRange[1]
                        self.updateUserSelectionLutProperties()
                    self.scaleTransferFunction.Points = self.userSelScalePoints
                else:
                    self.scaleTransferFunction.Points = buildLinearPiecewiseFunctionPoints(
                        dataRange, sizeRange, scaleFunction)

                self.representation.ScaleTransferFunction = self.scaleTransferFunction
                self.representation.SetScaleArray = config['pointSizeBy']
                self.representation.ScaleByArray = 1
            else:
                self.representation.GaussianRadius = constPointSize / 3.0
                self.representation.ScaleByArray = 0

            # vary opacity with array, maybe.
            if config['opacityBy'] and config['opacityBy'] != '' and config['opacityBy'] != USER_SELECTION \
                and (config['colorBy'] != USER_SELECTION):
                dataRange = self.dataTable.GetColumnByName(
                    config['opacityBy']).GetRange()
                opacityFunction = str(config['opacityFunction'])

                self.opacityTransferFunction.Points = buildLinearPiecewiseFunctionPoints(
                    dataRange, [0.0, 1.0], opacityFunction)

                self.representation.OpacityTransferFunction = self.opacityTransferFunction
                self.representation.OpacityArray = config['opacityBy']
                self.representation.OpacityByArray = 1
            else:
                self.representation.OpacityByArray = 0
                self.representation.Opacity = 1.0
        else:
            self.representation.Representation = 'Surface'
            self.representation.PointSize = pointSize
            self.representation.Opacity = 1.0

        self.representation.Visibility = 1

        # Mesh handling
        if self.dataMesh:
            if showMesh:
                if not self.meshRepresentation:
                    self.meshRepresentation = simple.Show(
                        self.dataMesh, self.renderView)
                    self.meshRepresentation.Opacity = 0.5

                self.meshRepresentation.Visibility = 1
                self.updateAxis(True)
            elif self.meshRepresentation:
                self.meshRepresentation.Visibility = 0

        self.getApplication().InvokeEvent('UpdateEvent')

        return {'success': True}
Exemplo n.º 5
0
    def updateScatterPlot(self, config):
        updateAxes = False
        updateColormap = False

        if not self.dataTable:
            # initialize everything
            self.dataTable = vtk.vtkTable()
            self.dataTable.ShallowCopy(self.divvyProtocol.getData())

            # copy data from the main protocol, and set up pipelilne
            trivProducer = simple.TrivialProducer()
            trivProducer.GetClientSideObject().SetOutput(self.dataTable)

            self.tableToPoints = simple.TableToPoints(Input=trivProducer)
            self.tableToPoints.XColumn = config['x']
            self.tableToPoints.YColumn = config['y']
            self.tableToPoints.ZColumn = config['z']
            self.tableToPoints.KeepAllDataArrays = 1

            self.tableToPoints.UpdatePipeline()

            self.representation = simple.GetRepresentation(
                self.tableToPoints, self.renderView)
            self.representation.Representation = 'Surface'
            self.representation.PointSize = 5
            self.representation.Opacity = 1.0

            self.representation.Visibility = 1

            self.renderView.AxesGrid = 'GridAxes3DActor'
            self.renderView.AxesGrid.Visibility = 1
            self.renderView.AxesGrid.XTitleColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.YTitleColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.ZTitleColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.GridColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.ShowGrid = 1
            self.renderView.AxesGrid.XLabelColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.YLabelColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.ZLabelColor = [0.0, 0.0, 0.0]
            self.renderView.AxesGrid.DataScale = [1, 1, 1]

            self.renderView.OrientationAxesVisibility = 0
            self.renderView.Background = [1.0, 1.0, 1.0]

            # create a LUT, if needed
            if 'colorBy' in config:
                vtkSMPVRepresentationProxy.SetScalarColoring(
                    self.representation.SMProxy, config['colorBy'], 0)
                vtkSMPVRepresentationProxy.RescaleTransferFunctionToDataRange(
                    self.representation.SMProxy, config['colorBy'], 0, False,
                    True)

            updateAxes = True
            updateColormap = True

        else:
            # update
            if self.arrays['x'] != config['x'] or \
              self.arrays['y'] != config['y'] or \
              self.arrays['z'] != config['z']:

                self.tableToPoints.XColumn = config['x']
                self.tableToPoints.YColumn = config['y']
                self.tableToPoints.ZColumn = config['z']

                self.dataTable.Modified()
                updateAxes = True

            if 'colorBy' in config and ( config['colorBy'] == USER_SELECTION or \
                 config['colorBy'] != \
                 vtkSMPVRepresentationProxy.GetArrayInformationForColorArray(self.representation.SMProxy).GetName()
                 or config['colorMapName'] != self._colorMapName) :
                updateColormap = True

        if updateAxes:
            self.arrays['x'] = config['x']
            self.arrays['y'] = config['y']
            self.arrays['z'] = config['z']
            self.renderView.AxesGrid.XTitle = config['x']
            self.renderView.AxesGrid.YTitle = config['y']
            self.renderView.AxesGrid.ZTitle = config['z']
            self.updateAxis()

        if updateColormap:
            vtkSMPVRepresentationProxy.SetScalarColoring(
                self.representation.SMProxy, config['colorBy'], 0)
            if config['colorBy'] == USER_SELECTION:
                # Coloring by the user selection needs special handling
                # if not self._selectionLutInitialized:
                #   self.updateUserSelectionLutProperties()
                pass
            else:
                vtkSMPVRepresentationProxy.RescaleTransferFunctionToDataRange(
                    self.representation.SMProxy, config['colorBy'], 0, False,
                    True)
                self.colorManager.selectColorMap(
                    self.representation.GetGlobalIDAsString(),
                    config['colorMapName'])

        return {'success': True}