def getVtkPolyDataFromNumpyPoints(points): ''' Given an Nx3 array of xyz points Return a new vtkPolyData containing points and vertex cells. If the input points is not float64 it will be converted first. ''' if points.dtype != np.float64: points = points.astype(np.float64) polyData = vtk.vtkPolyData() polyData.SetPoints(getVtkPointsFromNumpy(points)) vtk.vtkPCLConversions.AddVertexCells(polyData) return polyData
def getPlanPoseMeshes(self, messages, jointController, robotModel, numberOfSamples): poseTimes, poses = self.getPlanPoses(messages) f = self.getPoseInterpolator(poseTimes, poses) sampleTimes = np.linspace(poseTimes[0], poseTimes[-1], numberOfSamples) meshes = [] for sampleTime in sampleTimes: pose = f(sampleTime) jointController.setPose('plan_playback', pose) polyData = vtk.vtkPolyData() robotModel.model.getModelMesh(polyData) meshes.append(polyData) return meshes
def numpyToPolyData(pts, pointData=None, createVertexCells=False): pd = vtk.vtkPolyData() pd.SetPoints(vtk.vtkPoints()) # Makes a deep copy pd.GetPoints().SetData(getVtkFromNumpy(pts.copy())) if pointData is not None: for key, value in pointData.iteritems(): addNumpyToVtk(pd, value.copy(), key) if createVertexCells: cellIds = vtk.vtkIdList() cellIds.SetNumberOfIds(pd.GetNumberOfPoints()) for i in range(pd.GetNumberOfPoints()): cellIds.SetId(i, i) cells = vtk.vtkCellArray() cells.InsertNextCell(cellIds) pd.SetVerts(cells) return pd