示例#1
0
 def visible_pick_call_back(picker, event_id):
     x0, y0, x1, y1 = renderer.get_pick_position()
     selector = vtk.vtkOpenGLHardwareSelector()
     selector.SetFieldAssociation(
         vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS)
     selector.SetRenderer(renderer)
     selector.SetArea(x0, y0, x1, y1)
     selection = selector.Select()
     picked = pyvista.MultiBlock()
     for node in range(selection.GetNumberOfNodes()):
         cellids = selection.GetNode(node)
         if cellids is None:
             # No selection
             continue
         smesh = cellids.GetProperties().Get(vtk.vtkSelectionNode.PROP(
         )).GetMapper().GetInputAsDataSet()
         selection_filter = vtk.vtkSelection()
         selection_filter.AddNode(cellids)
         extract = vtk.vtkExtractSelectedIds()
         extract.SetInputData(0, smesh)
         extract.SetInputData(1, selection_filter)
         extract.Update()
         picked.append(pyvista.wrap(extract.GetOutput()))
     if len(picked) == 1:
         self.picked_cells = picked[0]
     else:
         self.picked_cells = picked
     return end_pick_helper(picker, event_id)
示例#2
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkExtractSelectedIds(), 'Processing.',
         ('vtkDataSet', 'vtkSelection'), ('vtkDataSet',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
示例#3
0
    def setup(self):

        self.CLselS = vtk.vtkSelectionSource()
        self.CLselS.SetContentType(
            4
        )  # vtkSelection:: #1 GLOBALIDS(nada) #3 VALUES(nada) #4 INDICES(varios)
        self.CLselS.SetFieldType(1)  # vtkSelection:: #0 CELL #1 POINT
        self.CLselS.SetContainingCells(
            0)  # para non extraer tamén as celdas que conteñen o punto dado

        self.CLselF = vtk.vtkExtractSelectedIds()
        self.CLselF.SetInputConnection(self.src.GetOutputPort())
        self.CLselF.SetSelectionConnection(self.CLselS.GetOutputPort())

        self.CLlabelsbM = vtk.vtkLabeledDataMapper()
        self.CLlabelsbM.SetInputConnection(self.CLselF.GetOutputPort())
        # self.CLlabelsbM.SetLabelFormat("%g")
        self.CLlabelsbM.SetLabelModeToLabelScalars()
        self.CLlabelsbM.GetLabelTextProperty().SetColor(Plot.label_color)

        self.CLlabelsbA = vtk.vtkActor2D()
        self.CLlabelsbA.SetMapper(self.CLlabelsbM)
        #        self.CLlabelsbA.SetVisibility(0)
        self.renderer.AddActor(self.CLlabelsbA)

        self.iren.AddObserver("LeftButtonPressEvent", self.ButtonPress)
        self.iren.AddObserver("LeftButtonReleaseEvent", self.ButtonRelease)

        self.picker = vtk.vtkPointPicker()
        #        picker.SetTolerance(0.005)
        self.picker.AddObserver("EndPickEvent", self.EndPick)
        self.iren.SetPicker(self.picker)
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkExtractSelectedIds(),
                                       'Processing.',
                                       ('vtkDataSet', 'vtkSelection'),
                                       ('vtkDataSet', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
示例#5
0
 def visible_pick_call_back(picker, event_id):
     x0,y0,x1,y1 = self.get_pick_position()
     selector = vtk.vtkOpenGLHardwareSelector()
     selector.SetFieldAssociation(vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS)
     selector.SetRenderer(self.renderer)
     selector.SetArea(x0,y0,x1,y1)
     cellids = selector.Select().GetNode(0)
     if cellids is None:
         # No selection
         return
     selection = vtk.vtkSelection()
     selection.AddNode(cellids)
     extract = vtk.vtkExtractSelectedIds()
     extract.SetInputData(0, mesh)
     extract.SetInputData(1, selection)
     extract.Update()
     self.picked_cells = pyvista.wrap(extract.GetOutput())
     return end_pick_helper(picker, event_id)
    def _CreateSkeleton(self):
        """Create the structure of the output vtkUnstructuredGrid and a map
        from the index of a point in the extraction file to the corresponding
        cellId in the skeleton.
        
        This method should only be called if the extraction object this 
        instance is working on has changed since the last time this method was
        called.
        """
        input = self.GetUnstructuredGridInput()

        # Get the centres as these should match the extracted property positions
        centers = vtk.vtkCellCenters()
        if vtk.vtkVersion().GetVTKMajorVersion() <= 5:
            centers.SetInput(input)
        else:
            centers.SetInputData(input)
        #centers.SetInput(input)
        centers.Update()
        # Use this to find the cell ID for each point.
        locator = vtk.vtkOctreePointLocator()
        locator.SetDataSet(centers.GetOutput())
        locator.BuildLocator()
        # Should be fine enough
        locator.SetTolerance(0.1 * self.Extracted.voxelSizeMetres)

        # Get the first set of extracted data from the file. We don't care
        # which as we only want to use the positions.
        extracted_positions = self.Extracted.GetByIndex(0).position
        nExtractedPoints = len(extracted_positions)

        # Make a list of the cell ids to keep; i.e. the cell in the input
        # (whole geometry) with ID cellIdsGmy[i] contains  the point given by
        # extracted_positions[i]
        gmyCellIdsByInput = vtk.vtkIdTypeArray()
        gmyCellIdsByInput.SetNumberOfComponents(1)
        gmyCellIdsByInput.SetNumberOfTuples(nExtractedPoints)

        gmyCellIdsByInputNp = numpy_support.vtk_to_numpy(gmyCellIdsByInput)

        for i, point in enumerate(extracted_positions):
            # Get cell in geometry corresponding to the point
            cellId = locator.FindClosestPoint(point)

            if cellId == -1:
                raise ValueError("Can't find cell for point at " + str(point))

            gmyCellIdsByInputNp[i] = cellId

        # Make an object to select only the cell ids we want
        selector = vtk.vtkSelectionNode()
        selector.SetFieldType(CELL)
        selector.SetContentType(INDICES)
        selector.SetSelectionList(gmyCellIdsByInput)

        # Make an object to hold the selector
        selectors = vtk.vtkSelection()
        selectors.AddNode(selector)

        # Perform the selection
        extractSelection = vtk.vtkExtractSelectedIds()
        if vtk.vtkVersion().GetVTKMajorVersion() <= 5:
            extractSelection.SetInput(0, input)
            extractSelection.SetInput(1, selectors)
        else:
            extractSelection.SetInputData(0, input)
            extractSelection.SetInputData(1, selectors)
        extractSelection.Update()

        gmyCellIdsByOutput = extractSelection.GetOutput().GetCellData(
        ).GetArray('vtkOriginalCellIds')

        gmyCellIdsByOutputNp = numpy_support.vtk_to_numpy(gmyCellIdsByOutput)

        self.OutputCellIdsByInputIndex = MatchCorresponding(
            gmyCellIdsByOutputNp, gmyCellIdsByInputNp)

        # Create the skeleton data object and only copy in the structure.
        self.Skeleton = vtk.vtkUnstructuredGrid()
        self.Skeleton.CopyStructure(extractSelection.GetOutput())
        return
示例#7
0
    def setup(self):

        self.CLselS = vtk.vtkSelectionSource()
        self.CLselS.SetContentType(
            4
        )  # vtkSelection:: #1 GLOBALIDS(nada) #3 VALUES(nada) #4 INDICES(varios)
        self.CLselS.SetFieldType(1)  # vtkSelection:: #0 CELL #1 POINT
        self.CLselS.SetContainingCells(
            0)  # para non extraer tamén as celdas que conteñen o punto dado

        self.CLselF = vtk.vtkExtractSelectedIds()
        self.CLselF.SetInputConnection(self.src.GetOutputPort())
        self.CLselF.SetSelectionConnection(self.CLselS.GetOutputPort())

        # marcar puntos
        if True:
            # puntos. tamanho en pantalla constante
            #            self.CLPointsV = vtk.vtkVertexGlyphFilter()
            #            self.CLPointsV.SetInputConnection(self.CLselF.GetOutputPort())
            #            self.CLPointsM = vtk.vtkPolyDataMapper()
            #            self.CLPointsM.SetInputConnection(self.CLPointsV.GetOutputPort())
            #            self.CLPointsM.ScalarVisibilityOff()
            self.CLPointsM = vtk.vtkDataSetMapper()
            self.CLPointsM.SetInputConnection(self.CLselF.GetOutputPort())
            self.CLPointsM.ScalarVisibilityOff()
            self.CLPointsA = vtk.vtkActor()
            self.CLPointsA.SetMapper(self.CLPointsM)
            self.CLPointsA.GetProperty().SetRepresentationToPoints()
            self.CLPointsA.GetProperty().SetPointSize(3.0)
            self.CLPointsA.GetProperty().SetColor(Plot.points_color)
            self.renderer.AddActor(self.CLPointsA)
        else:
            # esferas. tamanho en pantalla variable
            self.CLglyph = vtk.vtkSphereSource()
            self.CLPointsG = vtk.vtkGlyph3D()
            self.CLPointsG.SetInputConnection(self.CLselF.GetOutputPort())
            self.CLPointsG.SetSourceConnection(self.CLglyph.GetOutputPort())
            self.CLPointsG.ScalingOff()
            #self.CLPointsG.SetScaleModeToDataScalingOff()
            self.CLPointsM = vtk.vtkPolyDataMapper()
            self.CLPointsM.SetInputConnection(self.CLPointsG.GetOutputPort())
            self.CLPointsM.ScalarVisibilityOff()
            self.CLPointsA = vtk.vtkActor()
            self.CLPointsA.SetMapper(self.CLPointsM)
            self.CLPointsA.GetProperty().SetColor(Plot.points_color)
            self.renderer.AddActor(self.CLPointsA)

# labels
        self.CLlabelsbM = vtk.vtkLabeledDataMapper()
        self.CLlabelsbM.SetInputConnection(self.CLselF.GetOutputPort())
        # self.CLlabelsbM.SetLabelFormat("%g")
        if self.mode == 0:
            self.CLlabelsbM.SetLabelModeToLabelScalars()
        elif self.mode == 1:
            self.CLlabelsbM.SetLabelModeToLabelVectors()
        self.CLlabelsbM.GetLabelTextProperty().SetColor(Plot.label_color)

        self.CLlabelsbA = vtk.vtkActor2D()
        self.CLlabelsbA.SetMapper(self.CLlabelsbM)
        #        self.CLlabelsbA.SetVisibility(0)
        self.renderer.AddActor(self.CLlabelsbA)

        # point locator
        self.point_locator = vtk.vtkPointLocator()
        self.point_locator_pending = True

        self.iren.AddObserver("LeftButtonPressEvent", self.ButtonPress)
        self.iren.AddObserver("LeftButtonReleaseEvent", self.ButtonRelease)

        self.picker = vtk.vtkPropPicker()
        #        picker.SetTolerance(0.005)
        self.picker.AddObserver("EndPickEvent", self.EndPick)
        self.iren.SetPicker(self.picker)
示例#8
0
    def setup(self):
        
        # temporal HACK does not work
        #self.cellcenters = None
        #if self.pointcell == 1:
        #    self.cellcenters = vtk.vtkCellCenters()
        #    self.cellcenters.SetInputConnection(self.src.GetOutputPort())
        #    self.pointcell = 0
    
        self.CLselS = vtk.vtkSelectionSource()
        self.CLselS.SetContentType(4) # vtkSelection:: #1 GLOBALIDS(nada) #3 VALUES(nada) #4 INDICES(varios)
        if self.pointcell == 0:
            self.CLselS.SetFieldType(1) # vtkSelection:: #0 CELL #1 POINT
            self.CLselS.SetContainingCells(0) # para non extraer tamén as celdas que conteñen o punto dado
        elif self.pointcell == 1:
            self.CLselS.SetFieldType(0) # vtkSelection:: #0 CELL #1 POINT

        self.CLselF = vtk.vtkExtractSelectedIds()
#        if self.cellcenters is not None:
#            self.CLselF.SetInputConnection(self.cellcenters.GetOutputPort())
#        else:
#            self.CLselF.SetInputConnection(self.src.GetOutputPort())
        
        self.CLselF.SetInputConnection(self.src.GetOutputPort())
        self.CLselF.SetSelectionConnection(self.CLselS.GetOutputPort())
        
        if self.pointcell == 1:
            self.cellcenters = vtk.vtkCellCenters()
            self.cellcenters.VertexCellsOn() # que ?
            self.cellcenters.SetInputConnection(self.CLselF.GetOutputPort())
            
        
# marcar puntos
        if True:
            # puntos. tamanho en pantalla constante
#            self.CLPointsV = vtk.vtkVertexGlyphFilter()
#            self.CLPointsV.SetInputConnection(self.CLselF.GetOutputPort())
#            self.CLPointsM = vtk.vtkPolyDataMapper()
#            self.CLPointsM.SetInputConnection(self.CLPointsV.GetOutputPort())
#            self.CLPointsM.ScalarVisibilityOff()
            self.CLPointsM = vtk.vtkDataSetMapper()
            if self.pointcell == 1:
                self.CLPointsM.SetInputConnection(self.cellcenters.GetOutputPort())
            else:
                self.CLPointsM.SetInputConnection(self.CLselF.GetOutputPort())
            self.CLPointsM.ScalarVisibilityOff()
            self.CLPointsA = vtk.vtkActor()
            self.CLPointsA.SetMapper(self.CLPointsM)
            self.CLPointsA.GetProperty().SetRepresentationToPoints()
            self.CLPointsA.GetProperty().SetPointSize(3.0)
            self.CLPointsA.GetProperty().SetColor(Plot.points_color)
            self.renderer.AddActor(self.CLPointsA)
        else:
            # esferas. tamanho en pantalla variable
            self.CLglyph = vtk.vtkSphereSource()
            self.CLPointsG = vtk.vtkGlyph3D()
            self.CLPointsG.SetInputConnection(self.CLselF.GetOutputPort())
            self.CLPointsG.SetSourceConnection(self.CLglyph.GetOutputPort())
            self.CLPointsG.ScalingOff()
            #self.CLPointsG.SetScaleModeToDataScalingOff()
            self.CLPointsM = vtk.vtkPolyDataMapper()
            self.CLPointsM.SetInputConnection(self.CLPointsG.GetOutputPort())
            self.CLPointsM.ScalarVisibilityOff()
            self.CLPointsA = vtk.vtkActor()
            self.CLPointsA.SetMapper(self.CLPointsM)
            self.CLPointsA.GetProperty().SetColor(Plot.points_color)
            self.renderer.AddActor(self.CLPointsA)
        
# labels
        # protesta por que:
        # ..\archive\VTK\Rendering\vtkLabeledDataMapper.cxx, line 377
        # vtkLabeledDataMapper (094D4C80): Could not find label array (index 0) in input.        
        self.CLlabelsbM = vtk.vtkLabeledDataMapper()

#FIX FIX FIX
        if self.pointcell == 1:
            #self.cellcenters = vtk.vtkCellCenters()
            #self.cellcenters.SetInputConnection(self.CLselF.GetOutputPort())
            #self.CLlabelsbM.SetInputConnection(self.cellcenters.GetOutputPort())
            
            self.CLlabelsbM.SetInputConnection(self.cellcenters.GetOutputPort())
        else:
            self.CLlabelsbM.SetInputConnection(self.CLselF.GetOutputPort())
            
        # self.CLlabelsbM.SetLabelFormat("%g")
        if self.mode == 0:
            self.CLlabelsbM.SetLabelModeToLabelScalars()
        elif self.mode == 1:
            self.CLlabelsbM.SetLabelModeToLabelVectors()
        self.CLlabelsbM.GetLabelTextProperty().SetColor(Plot.label_color)

        self.CLlabelsbA = vtk.vtkActor2D()
        self.CLlabelsbA.SetMapper(self.CLlabelsbM)
#        self.CLlabelsbA.SetVisibility(0)
        self.renderer.AddActor(self.CLlabelsbA)
        
        # point locator
        if self.pointcell == 0:
            self.locator = vtk.vtkPointLocator()
        elif self.pointcell == 1:
            self.locator = vtk.vtkCellLocator()

        self.locator_pending = True

        if self.click == 0:
            self.iren.AddObserver("LeftButtonPressEvent", self.ButtonPress1)
        elif self.click == 1:
            self.iren.AddObserver("LeftButtonPressEvent", self.ButtonPress2)
            self.iren.AddObserver("LeftButtonReleaseEvent", self.ButtonRelease2)

        self.picker = vtk.vtkPropPicker()
#        picker.SetTolerance(0.005)
        self.picker.AddObserver("EndPickEvent", self.EndPick)
        self.iren.SetPicker(self.picker)
    def _CreateSkeleton(self):
        """Create the structure of the output vtkUnstructuredGrid and a map
        from the index of a point in the extraction file to the corresponding
        cellId in the skeleton.
        
        This method should only be called if the extraction object this 
        instance is working on has changed since the last time this method was
        called.
        """
        input = self.GetUnstructuredGridInput()
        
        # Get the centres as these should match the extracted property positions
        centers = vtk.vtkCellCenters()
        if vtk.vtkVersion().GetVTKMajorVersion() <= 5:
          centers.SetInput( input );
        else:
          centers.SetInputData( input );
        #centers.SetInput(input)
        centers.Update()
        # Use this to find the cell ID for each point.
        locator = vtk.vtkOctreePointLocator()
        locator.SetDataSet(centers.GetOutput())
        locator.BuildLocator()
        # Should be fine enough
        locator.SetTolerance(0.1 * self.Extracted.voxelSizeMetres)

        # Get the first set of extracted data from the file. We don't care
        # which as we only want to use the positions.
        extracted_positions = self.Extracted.GetByIndex(0).position
        nExtractedPoints = len(extracted_positions)
        
        # Make a list of the cell ids to keep; i.e. the cell in the input 
        # (whole geometry) with ID cellIdsGmy[i] contains  the point given by
        # extracted_positions[i]
        gmyCellIdsByInput = vtk.vtkIdTypeArray()
        gmyCellIdsByInput.SetNumberOfComponents(1)
        gmyCellIdsByInput.SetNumberOfTuples(nExtractedPoints)
        
        
        gmyCellIdsByInputNp = numpy_support.vtk_to_numpy(gmyCellIdsByInput)
         
        for i, point in enumerate(extracted_positions):
            # Get cell in geometry corresponding to the point
            cellId = locator.FindClosestPoint(point)

            if cellId == -1:
                raise ValueError("Can't find cell for point at " + str(point))

            gmyCellIdsByInputNp[i] = cellId
        
        # Make an object to select only the cell ids we want
        selector = vtk.vtkSelectionNode()
        selector.SetFieldType(CELL)
        selector.SetContentType(INDICES)
        selector.SetSelectionList(gmyCellIdsByInput)
        
        # Make an object to hold the selector
        selectors = vtk.vtkSelection()
        selectors.AddNode(selector)
        
        # Perform the selection
        extractSelection = vtk.vtkExtractSelectedIds()
        if vtk.vtkVersion().GetVTKMajorVersion() <= 5:        
            extractSelection.SetInput(0, input)
            extractSelection.SetInput(1, selectors)
        else:
            extractSelection.SetInputData(0, input)
            extractSelection.SetInputData(1, selectors)
        extractSelection.Update()
        
        gmyCellIdsByOutput = extractSelection.GetOutput().GetCellData().GetArray('vtkOriginalCellIds')
        
        
        gmyCellIdsByOutputNp = numpy_support.vtk_to_numpy(gmyCellIdsByOutput)
        
        self.OutputCellIdsByInputIndex = MatchCorresponding(gmyCellIdsByOutputNp,gmyCellIdsByInputNp)
        
        # Create the skeleton data object and only copy in the structure.
        self.Skeleton = vtk.vtkUnstructuredGrid()
        self.Skeleton.CopyStructure(extractSelection.GetOutput())
        return