Пример #1
0
    def intersect(self,Cy):
        """ Find intersection with an other cycle

        Parameters
        ----------
        Cy : Cycle

        Returns
        -------

        flip  : boolean
                indicates the orientation of the common brin
                True : flipped direction
                False : same direction
        brin  : common portion of th

        Notes
        -----

        flip,path = C1.intersect(C2)

        if flip == True --> The 2 cycles have a reverse travel
        direction for the common path

        path is the common path along the cycle

        """
        #
        # segment number
        #
        e1  = self.edges
        e2  = Cy.edges
        #
        # point number
        #
        v1  = self.vertices
        v2  = Cy.vertices
        #
        # intersection of segments and vertices
        #
        u   = np.intersect1d(e1,e2)
        v   = np.intersect1d(v1,v2)
        #
        Nis  = len(u)
        Nip  = len(v)
        #print Nis," segments en commun"
        if Nis>0:
            if Nis>1:
                brin1 = self.cycle
                brin2 = Cy.cycle
                if max(pyu.corrcy(brin1,brin2))>max(pyu.corrcy(brin1,brin2[::-1])):
                    flip = False
                else:
                    flip = True
                brin = u
            else:
                v   = np.intersect1d(v1,v2)
                tk1 = np.array([],dtype=int)
                tk2 = np.array([],dtype=int)
                for kv in v:
                    ik1 = np.nonzero(v1==kv)[0]
                    ik2 = np.nonzero(v2==kv)[0]
                    tk1 = np.hstack((tk1,ik1))
                    tk2 = np.hstack((tk2,ik2))
                dtk1 = tk1[1]-tk1[0]
                dtk2 = tk2[1]-tk2[0]
                if abs(dtk1)>1:
                    dtk1 = -dtk1
                if abs(dtk2)>1:
                    dtk2 = -dtk2
                if dtk1*dtk2>0:
                #    print "meme sens"
                    flip = False
                else:
                #    print "sens oppose"
                    flip = True

                brin = u
        else:
            flip  = False
            if Nip > 1:
                brin  = np.array([])
            else:
                brin  = v

        return(flip,brin)
Пример #2
0
    def intersect(self, Cy):
        """ Find intersection with an other cycle

        Parameters
        ----------
        Cy : Cycle 

        Returns
        -------

        flip  :
        brin  :

        Notes 
        ------

        flip,path = C1.intersect(C2)

        if flip == True --> The 2 cycles have a reverse travel
        direction for the common path

        path is the common path along the cycle

        """
        e1 = self.edges
        e2 = Cy.edges
        v1 = self.vertices
        v2 = Cy.vertices
        u = np.intersect1d(e1, e2)
        Ni = len(u)
        #print Ni," segments en commun"
        if Ni > 0:
            if Ni > 1:
                brin1 = self.cycle
                brin2 = Cy.cycle
                ####
                #### Faux
                ####
                #tk1 = np.array([],dtype=int)
                #tk2 = np.array([],dtype=int)
                #for ku in u:
                #    ik1 = np.nonzero(e1==ku)[0]
                #    ik2 = np.nonzero(e2==ku)[0]
                #    tk1 = np.hstack((tk1,ik1))
                #    tk2 = np.hstack((tk2,ik2))
                #tk1.sort()
                #tk2.sort()
                #brin1 = e1[tk1]
                #brin2 = e2[tk2]
                #if Ni==2:
                #    if prod(brin1==brin2):
                #        flip = False
                #    else:
                #        flip = True
                #else:
                if max(pyu.corrcy(brin1, brin2)) > max(
                        pyu.corrcy(brin1, brin2[::-1])):
                    flip = False
                else:
                    flip = True
                brin = u
            else:
                v = np.intersect1d(v1, v2)
                tk1 = np.array([], dtype=int)
                tk2 = np.array([], dtype=int)
                for kv in v:
                    ik1 = np.nonzero(v1 == kv)[0]
                    ik2 = np.nonzero(v2 == kv)[0]
                    tk1 = np.hstack((tk1, ik1))
                    tk2 = np.hstack((tk2, ik2))
                dtk1 = tk1[1] - tk1[0]
                dtk2 = tk2[1] - tk2[0]
                if abs(dtk1) > 1:
                    dtk1 = -dtk1
                if abs(dtk2) > 1:
                    dtk2 = -dtk2
                if dtk1 * dtk2 > 0:
                    #    print "meme sens"
                    flip = False
                else:
                    #    print "sens oppose"
                    flip = True

                #tk1.sort()
                #tk2.sort()
                #brin1 = v1[tk1]
                #brin2 = v2[tk2]
                #print brin1,brin2
                #if max(corrcy(brin1,brin2))>max(corrcy(brin1,brin2[::-1])):
                #    flip = False
                #else:
                #    flip = True
                brin = u
        else:
            flip = False
            brin = np.array([])

        return (flip, brin)
Пример #3
0
    def intersect(self, Cy):
        """ Find intersection with an other cycle

        Parameters
        ----------
        Cy : Cycle

        Returns
        -------

        flip  : boolean
                indicates the orientation of the common brin
                True : flipped direction
                False : same direction
        brin  : common portion of th

        Notes
        -----

        flip,path = C1.intersect(C2)

        if flip == True --> The 2 cycles have a reverse travel
        direction for the common path

        path is the common path along the cycle

        """
        #
        # segment number
        #
        e1 = self.edges
        e2 = Cy.edges
        #
        # point number
        #
        v1 = self.vertices
        v2 = Cy.vertices
        #
        # intersection of segments and vertices
        #
        u = np.intersect1d(e1, e2)
        v = np.intersect1d(v1, v2)
        #
        Nis = len(u)
        Nip = len(v)
        #print Nis," segments en commun"
        if Nis > 0:
            if Nis > 1:
                brin1 = self.cycle
                brin2 = Cy.cycle
                if max(pyu.corrcy(brin1, brin2)) > max(
                        pyu.corrcy(brin1, brin2[::-1])):
                    flip = False
                else:
                    flip = True
                brin = u
            else:
                v = np.intersect1d(v1, v2)
                tk1 = np.array([], dtype=int)
                tk2 = np.array([], dtype=int)
                for kv in v:
                    ik1 = np.nonzero(v1 == kv)[0]
                    ik2 = np.nonzero(v2 == kv)[0]
                    tk1 = np.hstack((tk1, ik1))
                    tk2 = np.hstack((tk2, ik2))
                dtk1 = tk1[1] - tk1[0]
                dtk2 = tk2[1] - tk2[0]
                if abs(dtk1) > 1:
                    dtk1 = -dtk1
                if abs(dtk2) > 1:
                    dtk2 = -dtk2
                if dtk1 * dtk2 > 0:
                    #    print "meme sens"
                    flip = False
                else:
                    #    print "sens oppose"
                    flip = True

                brin = u
        else:
            flip = False
            if Nip > 1:
                brin = np.array([])
            else:
                brin = v

        return (flip, brin)
Пример #4
0
    def intersect(self,Cy):
        """ Find intersection with an other cycle

        Parameters
        ----------
        Cy : Cycle 

        Returns
        -------

        flip  :
        brin  :

        Notes 
        ------

        flip,path = C1.intersect(C2)

        if flip == True --> The 2 cycles have a reverse travel
        direction for the common path

        path is the common path along the cycle

        """
        e1  = self.edges
        e2  = Cy.edges
        v1  = self.vertices
        v2  = Cy.vertices
        u   = np.intersect1d(e1,e2)
        Ni  = len(u)
        #print Ni," segments en commun"
        if Ni>0:
            if Ni>1:
                brin1 = self.cycle
                brin2 = Cy.cycle
                ####
                #### Faux
                ####
                #tk1 = np.array([],dtype=int)
                #tk2 = np.array([],dtype=int)
                #for ku in u:
                #    ik1 = np.nonzero(e1==ku)[0]
                #    ik2 = np.nonzero(e2==ku)[0]
                #    tk1 = np.hstack((tk1,ik1))
                #    tk2 = np.hstack((tk2,ik2))
                #tk1.sort()
                #tk2.sort()
                #brin1 = e1[tk1]
                #brin2 = e2[tk2]
                #if Ni==2:
                #    if prod(brin1==brin2):
                #        flip = False
                #    else:
                #        flip = True
                #else:
                if max(pyu.corrcy(brin1,brin2))>max(pyu.corrcy(brin1,brin2[::-1])):
                    flip = False
                else:
                    flip = True
                brin = u
            else:
                v   = np.intersect1d(v1,v2)
                tk1 = np.array([],dtype=int)
                tk2 = np.array([],dtype=int)
                for kv in v:
                    ik1 = np.nonzero(v1==kv)[0]
                    ik2 = np.nonzero(v2==kv)[0]
                    tk1 = np.hstack((tk1,ik1))
                    tk2 = np.hstack((tk2,ik2))
                dtk1 = tk1[1]-tk1[0]
                dtk2 = tk2[1]-tk2[0]
                if abs(dtk1)>1:
                    dtk1 = -dtk1
                if abs(dtk2)>1:
                    dtk2 = -dtk2
                if dtk1*dtk2>0:
                #    print "meme sens"
                    flip = False
                else:
                #    print "sens oppose"
                    flip = True

                #tk1.sort()
                #tk2.sort()
                #brin1 = v1[tk1]
                #brin2 = v2[tk2]
                #print brin1,brin2
                #if max(corrcy(brin1,brin2))>max(corrcy(brin1,brin2[::-1])):
                #    flip = False
                #else:
                #    flip = True
                brin = u
        else:
            flip  = False
            brin = np.array([])

        return(flip,brin)