def applyVoxelGrid(polyData, leafSize=0.01): v = vtk.vtkPCLVoxelGrid() v.SetLeafSize(leafSize, leafSize, leafSize) v.SetInputData(polyData) # regression: vtk6->5. was SetInput v.Update() return shallowCopy(v.GetOutput())
def readPolyData(filename, computeNormals=False): ext = os.path.splitext(filename)[1].lower() readers = { '.vtp' : vtk.vtkXMLPolyDataReader, '.vtk' : vtk.vtkPolyDataReader, '.ply' : vtk.vtkPLYReader, '.obj' : vtk.vtkOBJReader, '.stl' : vtk.vtkSTLReader, } try: readers['.pcd'] = vtk.vtkPCDReader except AttributeError: pass if ext not in readers: raise Exception('Unknown file extension in readPolyData: %s' % filename) reader = readers[ext]() reader.SetFileName(filename) reader.Update() polyData = shallowCopy(reader.GetOutput()) if computeNormals: return _computeNormals(polyData) else: return polyData
def readPolyData(filename, computeNormals=False): ext = os.path.splitext(filename)[1].lower() readers = { '.vtp': vtk.vtkXMLPolyDataReader, '.vtk': vtk.vtkPolyDataReader, '.ply': vtk.vtkPLYReader, '.obj': vtk.vtkOBJReader, '.stl': vtk.vtkSTLReader, } try: readers['.pcd'] = vtk.vtkPCDReader except AttributeError: pass if ext not in readers: raise Exception('Unknown file extension in readPolyData: %s' % filename) reader = readers[ext]() reader.SetFileName(filename) reader.Update() polyData = shallowCopy(reader.GetOutput()) if computeNormals: return _computeNormals(polyData) else: return polyData
def applyVoxelGrid(polyData, leafSize=0.01): v = vtk.vtkPCLVoxelGrid() v.SetLeafSize(leafSize, leafSize, leafSize) v.SetInput(polyData) v.Update() return shallowCopy(v.GetOutput())
def readPolyData(filename, computeNormals=False): ext = os.path.splitext(filename)[1].lower() readers = { ".vtp": vtk.vtkXMLPolyDataReader, ".vtk": vtk.vtkPolyDataReader, ".ply": vtk.vtkPLYReader, ".obj": vtk.vtkOBJReader, ".stl": vtk.vtkSTLReader, } try: readers[".pcd"] = vtk.vtkPCDReader except AttributeError: pass if ext not in readers: raise Exception("Unknown file extension in readPolyData: %s" % filename) reader = readers[ext]() reader.SetFileName(filename) reader.Update() polyData = shallowCopy(reader.GetOutput()) if ext == ".ply": vtk.vtkPCLConversions.AddVertexCells(polyData) if computeNormals: return _computeNormals(polyData) else: return polyData
def labelOutliers(dataObj, searchRadius=0.03, neighborsInSearchRadius=10): f = vtk.vtkPCLRadiusOutlierRemoval() f.SetInput(dataObj) f.SetSearchRadius(searchRadius) f.SetNeighborsInSearchRadius(int(neighborsInSearchRadius)) f.Update() return shallowCopy(f.GetOutput())
def applyEuclideanClustering(dataObj, clusterTolerance=0.05, minClusterSize=100, maxClusterSize=1e6): f = vtk.vtkPCLEuclideanClusterExtraction() f.SetInput(dataObj) f.SetClusterTolerance(clusterTolerance) f.SetMinClusterSize(int(minClusterSize)) f.SetMaxClusterSize(int(maxClusterSize)) f.Update() return shallowCopy(f.GetOutput())
def applyLineFit(dataObj, distanceThreshold=0.02): f = vtk.vtkPCLSACSegmentationLine() f.SetInput(dataObj) f.SetDistanceThreshold(distanceThreshold) f.Update() origin = np.array(f.GetLineOrigin()) direction = np.array(f.GetLineDirection()) return origin, direction, shallowCopy(f.GetOutput())
def labelPointDistanceAlongAxis(polyData, axis, origin=None, resultArrayName='distance_along_axis'): points = vtkNumpy.getNumpyFromVtk(polyData, 'Points') if origin is not None: points = points - origin distanceValues = np.dot(points, axis) if origin is None: distanceValues -= np.nanmin(distanceValues) newData = shallowCopy(polyData) vtkNumpy.addNumpyToVtk(newData, distanceValues, resultArrayName) return newData
def createAxesPolyData(scale, useTube, tubeWidth=0.002): axes = vtk.vtkAxes() axes.SetComputeNormals(0) axes.SetScaleFactor(scale) axes.Update() if useTube: tube = vtk.vtkTubeFilter() tube.SetInputConnection(axes.GetOutputPort()) tube.SetRadius(tubeWidth) tube.SetNumberOfSides(12) tube.Update() axes = tube return shallowCopy(axes.GetOutput())
def _createAxes(self, scale, useTube): axes = vtk.vtkAxes() axes.SetComputeNormals(0) axes.SetScaleFactor(scale) axes.Update() if useTube: tube = vtk.vtkTubeFilter() tube.SetInput(axes.GetOutput()) tube.SetRadius(0.002) tube.SetNumberOfSides(12) tube.Update() axes = tube return shallowCopy(axes.GetOutput())
def readMultiBlock(filename): '''Reads a .vtm file and returns a list of vtkPolyData objects''' reader = vtk.vtkXMLMultiBlockDataReader() reader.SetFileName(filename) reader.Update() polyDataList = [] mb = reader.GetOutput() for i in xrange(mb.GetNumberOfBlocks()): polyData = vtk.vtkPolyData.SafeDownCast(mb.GetBlock(i)) if polyData and polyData.GetNumberOfPoints(): polyDataList.append(shallowCopy(polyData)) return polyDataList
def readImage(filename): ext = os.path.splitext(filename)[1].lower() readers = { '.png' : vtk.vtkPNGReader, '.jpg' : vtk.vtkJPEGReader, } if ext not in readers: raise Exception('Unknown file extension in readImage: %s' % filename) reader = readers[ext]() reader.SetFileName(filename) reader.Update() image = shallowCopy(reader.GetOutput()) return image
def readImage(filename): ext = os.path.splitext(filename)[1].lower() readers = { '.png': vtk.vtkPNGReader, '.jpg': vtk.vtkJPEGReader, } if ext not in readers: raise Exception('Unknown file extension in readImage: %s' % filename) reader = readers[ext]() reader.SetFileName(filename) reader.Update() image = shallowCopy(reader.GetOutput()) return image
def addPolyData(self, polyData, color=[1,1,1], extraLabels=None): ''' Add a vtkPolyData to the debug data. A color can be provided. If the extraLabels argument is used, it should be a list of tuples, each tuple is (labelName, labelValue) where labelName is a string and labelValue is an int or float. An array with labelName will be filled with labelValue and added to the poly data. ''' polyData = shallowCopy(polyData) if color is not None: colorArray = np.empty((polyData.GetNumberOfPoints(), 3), dtype=np.uint8) colorArray[:,:] = np.array(color)*255 addNumpyToVtk(polyData, colorArray, 'RGB255') if extraLabels is not None: for labelName, labelValue in extraLabels: extraArray = np.empty((polyData.GetNumberOfPoints(), 1), dtype=type(labelValue)) extraArray[:] = labelValue addNumpyToVtk(polyData, extraArray, labelName) self.append.AddInput(polyData)
def _triangulate(polyData): normals = vtk.vtkTriangleFilter() normals.SetInput(polyData) normals.Update() return shallowCopy(normals.GetOutput())
def getPolyData(self): if self.append.GetNumberOfInputConnections(0): self.append.Update() return shallowCopy(self.append.GetOutput())
def _computeNormals(polyData): normals = vtk.vtkPolyDataNormals() normals.SetFeatureAngle(45) normals.SetInput(polyData) normals.Update() return shallowCopy(normals.GetOutput())