def extractClusters(polyData, clusterInXY=False, **kwargs):
    ''' Segment a single point cloud into smaller clusters
        using Euclidean Clustering
     '''

    if not polyData.GetNumberOfPoints():
        return []

    if (clusterInXY == True):
        ''' If Points are seperated in X&Y, then cluster outside this '''
        polyDataXY = vtk.vtkPolyData()
        polyDataXY.DeepCopy(polyData)
        points=vtkNumpy.getNumpyFromVtk(polyDataXY , 'Points') # shared memory
        points[:,2] = 0.0
        #showPolyData(polyDataXY, 'polyDataXY', visible=False, parent=getDebugFolder())
        polyDataXY = applyEuclideanClustering(polyDataXY, **kwargs)
        clusterLabels = vtkNumpy.getNumpyFromVtk(polyDataXY, 'cluster_labels')
        vtkNumpy.addNumpyToVtk(polyData, clusterLabels, 'cluster_labels')

    else:
        polyData = applyEuclideanClustering(polyData, **kwargs)
        clusterLabels = vtkNumpy.getNumpyFromVtk(polyData, 'cluster_labels')


    clusters = []
    for i in xrange(1, clusterLabels.max() + 1):
        cluster = thresholdPoints(polyData, 'cluster_labels', [i, i])
        clusters.append(cluster)
    return clusters
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
Example #3
0
    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)