Ejemplo n.º 1
0
 def _get_buff(self, width=None):
     import delaunay as de
     x0, x1 = self.xlim
     y0, y1 = self.ylim
     if width is None:
         l, b, width, height = _get_bounds(self._axes.bbox)
     else:
         height = width
     self.pix = (width,height)
     numPoints_x = int(width)
     numPoints_y = int(width)
     dx = numPoints_x / (x1-x0)
     dy = numPoints_y / (y1-y0)
     xlim = na.logical_and(self.data["px"]+2.0*self.data['pdx'] >= x0,
                           self.data["px"]-2.0*self.data['pdx'] <= x1)
     ylim = na.logical_and(self.data["py"]+2.0*self.data['pdy'] >= y0,
                           self.data["py"]-2.0*self.data['pdy'] <= y1)
     wI = na.where(na.logical_and(xlim,ylim))
     xi, yi = na.mgrid[0:numPoints_x, 0:numPoints_y]
     x = (self.data["px"][wI]-x0)*dx
     y = (self.data["py"][wI]-y0)*dy
     z = self.data[self.axis_names["Z"]][wI]
     if self.log_field: z=na.log10(z)
     buff = de.Triangulation(x,y).nn_interpolator(z)(xi,yi)
     buff = buff.clip(z.min(), z.max())
     if self.log_field: buff = 10**buff
     return buff.transpose()
Ejemplo n.º 2
0
def measure(object, sizeCutoff, measurements=zeros(1, dtype=measureDType)):
    #measurements = {}

    measurements['NEvents'] = object.shape[0]
    measurements['xPos'] = object[:, 0].mean()
    measurements['yPos'] = object[:, 1].mean()

    if object.shape[0] > 3:
        T = delaunay.Triangulation(object.ravel(), 2)
        P, A, triI = gen3DTriangs.gen2DTriangsTF(T, sizeCutoff)

        if not len(P) == 0:
            measurements['Area'] = A.sum() / 3

            #print triI

            extEdges = gen3DTriangs.getExternalEdges(triI)

            measurements['Perimeter'] = gen3DTriangs.getPerimeter(extEdges, T)
        else:
            measurements['Area'] = 0
            measurements['Perimeter'] = 0

        ms, sm = moments.calcMCCenteredMoments(object[:, 0], object[:, 1])
        #print ms.ravel()[3]
        #print ms.shape, measurements['moments'].shape
        measurements['moments'][:] = ms.ravel()
        measurements['momentErrors'][:] = sm.ravel()

    if object.shape[0] > 1:
        measureAligned(object, measurements)
    #measurements.update(measureAligned(object))
    return measurements
Ejemplo n.º 3
0
def calcEdgeDists(objects, objMeasures):
    T = delaunay.Triangulation(
        array([objMeasures['xPos'], objMeasures['yPos']]).T, 2)

    va = array(T.set)
    objInd = {}

    #dictionary mapping vertices to indicex
    for i in range(len(T.set)):
        #print tuple(T.set[i])
        objInd[tuple(va[i, :])] = i

    minEdgeDists = []

    for o, m in zip(objects, va):
        ed = 1e50
        for N in T.neighbours[tuple(m)]:
            iN = objInd[N]
            dx = o[:, 0][:, None] - objects[iN][:, 0][None, :]
            dy = o[:, 1][:, None] - objects[iN][:, 1][None, :]

            d = sqrt(dx**2 + dy**2)

            ed = min(ed, d.min())

        minEdgeDists.append(ed)

    return array(minEdgeDists)
Ejemplo n.º 4
0
def renderTetrahedra(im, y, x, z, scale = [1,1,1], pixelsize=[5,5,5]):
    T = delaunay.Triangulation(array([x/scale[0],y/scale[1],z/scale[2]]).T.ravel(),3)

    f = array(T.facets)

    x_ = scale[0]*f[:,:,0]/pixelsize[0]
    y_ = scale[1]*f[:,:,1]/pixelsize[1]
    z_ = scale[2]*f[:,:,2]/pixelsize[2]

    v = 1./(calcMeanEdge(f)**3)
    #v = 1./(1 + calcTetVolume(f))

    SoftRend.drawTetrahedra(im, x_, y_, z_, v)
Ejemplo n.º 5
0
def blobify(objects, sizeCutoff, sm=False, sc=[10, 10, 10]):
    P_ = []
    N_ = []
    A_ = []

    for i, o in enumerate(objects):
        if sm:
            #print o.shape
            x = o[:,0][:,None] + sc[0]*xs[None, :]
            y = o[:,1][:,None] + sc[1]*ys[None, :]
            z = o[:,2][:,None] + sc[2]*zs[None, :]

            #o = o + (sc[0]/10.)*random.normal(size=o.shape)

            o = vstack((x.ravel(), y.ravel(), z.ravel())).T
            #print o.shape


        T = delaunay.Triangulation(o.ravel(),3)
        #print T.indices
        #for ti in T.indices:
        #    print len(ti)
        P, A, N, triI = gen3DTriangsTF(T, sizeCutoff, internalCull=True)

        #P, A, N = removeInternalFaces(P, A, N)
        if not P == []:
            averageNormalsF(P, N,triI)

            #triS = triI.argsort()

            #print P[triS,:]
            #print N[triS,:]

            #print P.shape
            A = ones(A.shape)*i

            P_.append(P)
            N_.append(N)
            A_.append(A)

    return (vstack(P_), hstack(A_), vstack(N_))
Ejemplo n.º 6
0
def blobify2D(objects, sizeCutoff):
    P_ = []
    
    A_ = []

    for o, i in zip(objects, range(len(objects))):
        T = delaunay.Triangulation(o.ravel(),2)
        #T2 = matplotlib.delaunay.Triangulation(o[:, 0], o[:,1])
        P, A, triI = gen2DTriangsTF(T, sizeCutoff)

        #P, A, N = removeInternalFaces(P, A, N)

        #colour by object
        A = ones(A.shape)*i
        

        #print P.shape

        P_.append(P)
        
        A_.append(A)

    return (vstack(P_), hstack(A_))
Ejemplo n.º 7
0
def gen3DBlobs(x,y,z, sizeCutoff=inf, sm=False, sc=[10, 10, 10]):
    T = delaunay.Triangulation(array([x,y,z]).T.ravel(),3)

    objects = segment(T, sizeCutoff)

    return blobify(objects, sizeCutoff, sm, sc)
Ejemplo n.º 8
0
def gen3DTriangs(x,y,z, sizeCutoff=inf, internalCull=True, pcut=inf):
    T = delaunay.Triangulation(array([x,y,z]).T.ravel(),3)

    return gen3DTriangsTFC(T, sizeCutoff, internalCull, pcut=sizeCutoff)[:3]