if cellPicker.GetCellId() != -1: # print("Pick position is: ", cellPicker.GetPickPosition()) # print("Cell id is:", cellPicker.GetCellId()) # print("Point id is:", cellPicker.GetPointId()) if self.dataset isNone: print("Source data not found! ") return
cell = self.dataset.GetCell(cellPicker.GetCellId()) # 通过拾取的CellId获取vtkCell # 打印单元信息 self.textActor.SetInput(f"Picked Cell Type: {cell.GetClassName()}\nCell Id: {cellPicker.GetCellId()}") ## 高亮选择的单元方法1 # selectedCells = vtk.vtkUnstructuredGrid() # cellArray = vtk.vtkCellArray() # pointList = vtk.vtkPoints() # idList = vtk.vtkIdList() # points = cell.GetPoints() # num = points.GetNumberOfPoints() # p = [0.0, 0.0, 0.0] # for i in range(num): # p = points.GetPoint(i) # print(f"Point{i} :\tx = {p[0]}\ty = {p[1]}\tz ={p[2]}") # idList.InsertNextId(pointList.InsertNextPoint(p)) # selectedCells.SetPoints(pointList) # selectedCells.InsertNextCell(cell.GetCellType(), idList) # print(f"Number of points in the selection: {selectedCells.GetNumberOfPoints()}") # print(f"Number of cells in the selection : {selectedCells.GetNumberOfCells()}") # mapper = vtk.vtkDataSetMapper() # mapper.SetInputData(selectedCells) # self.GetDefaultRenderer().RemoveActor(self.selectedActor) # self.selectedActor.SetMapper(mapper) # self.selectedActor.GetProperty().EdgeVisibilityOn() # self.selectedActor.GetProperty().SetColor(1.0, 0.0, 0.0) # self.selectedActor.GetProperty().SetPointSize(5.0) # self.GetDefaultRenderer().AddActor(self.selectedActor)